盡少調(diào)用 plt.scatter 方法便可大幅提升性能.
詳解
假設(shè) WX_b 為 M N 矩陣, mx 為 M 1 矩陣, 下面代碼
for i in range(WX_b.shape[0]):
for j in range(WX_b.shape[1]):
plt.scatter(mx[i], WX_b[i][j])
可以優(yōu)化成
plt.scatter(mx.repeat(WX_b.shape[1], axis=1), WX_b)
jupyter 示例代碼
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
WX_b = np.random.randn(30, 5)
mx = np.random.randn(WX_b.shape[0], 1)
def func1():
for i in range(WX_b.shape[0]):
for j in range(WX_b.shape[1]):
plt.scatter(mx[i], WX_b[i][j])
def func2():
plt.scatter(mx.repeat(WX_b.shape[1], axis=1), WX_b)
%time func1()
%time func2()
參考結(jié)果: func2 運行時間大約是 func1 的 5%.
為啥要用1000臺服務(wù)器,是為了IP分散么?如果是這個目的建議改用代理池
你的帳號需要付款
3D圖形好像沒有填充方法,需要先轉(zhuǎn)換成3D Polygon。下面是我根據(jù)SO上的一個回答寫的一個測試,你自己體會一下吧。
注:這個方法來自SO,原帖地址:https://stackoverflow.com/que...,不明白的可以去原貼查看。
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
size = 40
x = [[0] * size] * size
y = list(map(sorted, np.random.rand(size, size)))
z = list(map(sorted, np.random.rand(size, size)))
vect = []
for i in range(size):
vect.append(list(zip(x[i], y[i], z[i])))
poly3dCollection = Poly3DCollection(vect)
fig = plt.figure()
ax = Axes3D(fig)
ax.add_collection3d(poly3dCollection)
ax.set_xlim([-1, 1])
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
plt.show()
python 基礎(chǔ)有待加強
#df = ts.get_tick_data('601688',date='begin.strftime("%Y-%m-%d")')
df = ts.get_tick_data('601688',date=begin.strftime("%Y-%m-%d"))
最好不要使用for循環(huán)。
df1['group'] = df1['add'].apply(lambda x: df2.loc[[y in x for y in df2['key_word']],'group']).stack().reset_index(name='group')['group']
更新:
另一種方法,處理未收錄的情況
def match_group(x):
for y in df2['key_word']:
if y in x:
return y
return '未收錄'
df1['group'] = df1['add'].apply(match_group)
不知道為什么,.show()
方法下載的圖片就不行。
使用以下代碼就好了
import matplotlib.pyplot as plt
plt.figure(1, facecolor = '#FF9966')
plt.savefig('test.png', facecolor=fig.get_facecolor())
HTTP 400 錯誤 - 請求無效 (Bad request) 可能是你的cookie有問題(可能是:語法無效、字段錯誤、字符錯誤等...),主要還是發(fā)請求錯誤
python 3.5環(huán)境 把chromedriver的路徑改成自己的就可以運行了
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
chrome_opt = webdriver.ChromeOptions()
prefs = {"profile.managed_default_content_settings.images":2}
chrome_opt.add_experimental_option("prefs", prefs)
browser = webdriver.Chrome(executable_path="E:\selenium\chromedriver.exe", chrome_options=chrome_opt)
browser.set_window_position(-10, 0)
pageNum = 1
countNum = 1
while True:
print("\n當前頁數(shù):%d"%pageNum)
browser.get("http://app2.sfda.gov.cn/datasearchp/gzcxSearch.do?page=%d&searchcx=&optionType=V1¶mter0=null¶mter1=null¶mter2=null&formRender=cx"%pageNum)
browser.execute_script("var q=document.documentElement.scrollTop=270")
allProduct = WebDriverWait(browser, 10).until(lambda x: x.find_elements_by_xpath('/html/body/center/table[4]/tbody/tr[2]/td/center/table/tbody/tr[3]/td/table[1]/tbody/tr'))
for product in allProduct:
if (product.get_attribute("name") != None):
cpmc = WebDriverWait(product, 10).until(lambda x: x.find_element_by_xpath('./td[1]')).text
gcyp = WebDriverWait(product, 10).until(lambda x: x.find_element_by_xpath('./td[2]/table/tbody/tr/td[2]/table/tbody/tr/td[2]/font')).text
jkyp = WebDriverWait(product, 10).until(lambda x: x.find_element_by_xpath('./td[2]/table/tbody/tr/td[4]/table/tbody/tr/td[2]/font')).text
ypgg = WebDriverWait(product, 10).until(lambda x: x.find_element_by_xpath('./td[2]/table/tbody/tr/td[6]/table/tbody/tr/td[2]/font')).text
print("編號:%s, 產(chǎn)品名稱:%s, 國產(chǎn)藥品:%s, 進口藥品:%s, 藥品廣告:%s"%(countNum, cpmc, gcyp, jkyp, ypgg))
countNum += 1
if (len(allProduct) != 30) : break
pageNum += 1
循環(huán)引用問題,已解決
es6 簡寫方式
可能有反爬蟲手段,selenium還是有些特征的,比如全局對象中會有一些特殊屬性。
因為你用 Apache 部署的時候,Python 環(huán)境是全局的,你的 conda 環(huán)境并沒有配置進去
看看這個答案能否解決你的問題
from selenium import webdriver
import time
with open('../password.txt', 'r') as r:
username, password = r.readline().split(',')
chrome = webdriver.Chrome()
chrome.get('https://www.itjuzi.com/user/login')
time.sleep(2)
chrome.find_element_by_xpath('//*[@id="create_account_email"]').send_keys(username)
chrome.find_element_by_xpath('//*[@id="create_account_password"]').send_keys(password)
chrome.find_element_by_xpath('//*[@id="login_btn"]').click()
最簡單的登陸方式
var nest_result=[];
function arrNestToNonNest(arr){
for(let item of arr){
nest_result.shift({"id":item.id,"title":item.title})
if(item.hasOwnProperty("child")){
arrNestToNonNest(item.child)
}
}
}
arrNestToNonNest(data)
var array1 = [{ id: '1' }, { id: '2' }, { id: '3' }];
var array2 = [{ id: '1' }];
function filter (...args) {
var map = {}
args.forEach(arr=>{
arr.forEach(v=>{
map[v.id] = v
})
})
return Object.entries(map).map(v=>v[1])
}
……我覺得Ls答案沒毛病啊,明明就是個匯總值,為什么要循環(huán)執(zhí)行echo
?
不太明白你這里的數(shù)據(jù)結(jié)構(gòu)是怎么規(guī)劃的……這里應(yīng)該是一個二維數(shù)組結(jié)構(gòu)吧。
另外看你上邊用了number_format
,這個輸出是個字符串,建議你在所有計算結(jié)束后頁面渲染前再用,因為計算機的原生浮點數(shù)在計算時會存在精度誤差(可以自己搜一下“IEEE754精度誤差”),另外類型也不對。
又不是 UA 的事。微信的環(huán)境有自己的東西,你要訪問的頁面,隨便一行 HAHAHA.XXX()
的調(diào)用,就可以判斷是不是微信環(huán)境。(因為瀏覽器是自己的, window
下有哪些 js api 都是自己控制的)
北大青鳥APTECH成立于1999年。依托北京大學優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學院和江蘇省首批服務(wù)外包人才培訓基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團,成為集合面授教學培訓、網(wǎng)
達內(nèi)教育集團成立于2002年,是一家由留學海歸創(chuàng)辦的高端職業(yè)教育培訓機構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
曾工作于聯(lián)想擔任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍懿科技有限責任公司從事總經(jīng)理職務(wù)負責iOS教學及管理工作。
浪潮集團項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風格 授課風格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。