-
print(np.random.rand(2,3)) print(np.random.randint(1,10,3)) print(np.random.randn(2,4)) print(np.random.choice([10,20,30]))
查看全部 -
Python數據分析庫1
查看全部 -
Python數據分析概述
查看全部 -
Python數據分析
查看全部 -
markmark
查看全部 -
插眼, pandas 真不錯
查看全部 -
....................
查看全部 -
...........
查看全部 -
lst.sum, lst.min, lst.min
中axis:
????- axis=0, 對最外層的每行進行操作
????- axis=1, 對倒數第二層的每行進行操作
查看全部 -
fig?=?plt.figure() ax?=?fig.add_subplot(3,?3,?1) n?=?128 X?=?np.random.normal(0,?1,?n) Y?=?np.random.normal(0,?1,?n) T?=?np.arctan2(Y,?X) #?plt.axes([0.025,?0.025,?0.95,?0.95]) ax.scatter(X,?Y,?s=75,?c=T,?alpha=.5) plt.xlim(-1.5,?1.5),?plt.xticks([]) plt.ylim(-1.5,?1.5),?plt.yticks([]) plt.axis() plt.title("scatter") plt.xlabel("x") plt.ylabel("y") #?bar fig.add_subplot(332) n?=?10 X?=?np.arange(n) Y1?=?(1?-?X?/?float(n)?*?np.random.uniform(0.5,?1.0,?n)) Y2?=?(1?-?X?/?float(n)?*?np.random.uniform(0.5,?1.0,?n)) plt.bar(X,?+Y1,?facecolor="#9999ff",?edgecolor="white") plt.bar(X,?-Y2,?facecolor="#ff9999",?edgecolor="white") for?x,?y?in?zip(X,?Y1): ????plt.text(x?+?0.4,?y?+?0.05,?'%.2f'?%?y,?ha='center',?va='bottom') for?x,?y?in?zip(X,?Y2): ????plt.text(x?+?0.4,?-y?-?0.05,?'%.2f'?%?y,?ha='center',?va='top') #?Pie fig.add_subplot(333) n?=?20 Z?=?np.ones(n) Z[-?1]?*=?2 plt.pie(Z,?explode=Z?*?.05,?colors=['%f'?%?(i?/?float(n))?for?i?in?range(n)], ????????labels=['%.2f'?%?(i?/?float(n))?for?i?in?range(n)]) plt.gca().set_aspect('equal') plt.xticks(),?plt.yticks([]) #?polar fig.add_subplot(334,?polar=True) n?=?20 theta?=?np.arange(0.0,?2?*?np.pi,?2?*?np.pi?/?n) radii?=?10?*?np.random.rand(n) #?plt.plot(theta,radii) plt.polar(theta,?radii) #?heatmap fig.add_subplot(335) from?matplotlib?import?cm data?=?np.random.rand(3,?3) cmap?=?cm.Blues map?=?plt.imshow(data,?interpolation='nearest',?cmap=cmap, ?????????????????aspect='auto',?vmin=0,?vmax=1) #?3D from?mpl_toolkits.mplot3d?import?Axes3D ax?=?fig.add_subplot(336,?projection="3d") ax.scatter(1,?1,?3,?s=100) #?hot?map fig.add_subplot(313) def?f(x,?y): ????return?(1?-?x?/?2?+?x?**?5?+?y?**?3)?*?np.exp(-x?**?2?-?y?**?2) n?=?256 x?=?np.linspace(-3,?3,?n) y?=?np.linspace(-3,?3,?n) X,?Y?=?np.meshgrid(x,?y) plt.contourf(X,?Y,?f(X,?Y),?8,?alpha=.75,?cmap=plt.cm.hot) plt.savefig("./fig.png") plt.show()
查看全部 -
numpy
關鍵詞:? 開源? 數據計算擴展
功能:? ? ?ndarray? ?多維操作? ?線性代數
官網:? ?http://www.numoy.org/
查看全部 -
an查看全部
-
#常用array操作?
list = ?(np.arange(1, 11)) #產生一個1-11(不含11)的等差數列
?list = ?(np.arange(1, 11)).reshape([2, 5]) # 變成兩行五列數組 ,reshape是一種函數,函數可以重新調整矩陣的行數、列數、維數。
print (np.exp(list)) ?# list 的自然指數?
print (np.exp2(list)) # list 的自然指數的平方?
print (np.sqrt(list)) # list 的開方
sum函數里面的axis是指定行或者列.
axis=0的話是按列求和, axis=1是按行求和
print (np.vstack((list1,list2))) # Vertical 垂直,即縱向連接
print (np.hstack((list1,list2))) #Horizontal 水平,即橫向連接
np.concatenate 兩個lst的追加?
np.vstack 追加 ?分成兩行?
np.hstack ?同concatenate的結果?
np.spilt 分成幾份數組
查看全部 -
np.zeros([2,?4])??全0數組 np.ones([3,?5])??全1數組 np.random.rand(2,?4)??均勻分布隨機數組 np.random.rand()??一個隨機數 np.random.randint(1,?10,?5)?在1到10之間生成5個隨機數 np.random.randn(2,?3)??標準正態隨機數
查看全部 -
導入模塊并簡稱:import numpy as np
np.array(list, dtype=np.類型)
np.array 用來創建一個numpy數組。?
np.shape 顯示np數組屬性?
np.ndim 表示數組維度
?np.dtype表示數組元素類型(如:int8,in16,float64等)?
np.itemsize表示數組元素所占字節大小,如float64占字節8位 np.size表示數組元素個數
查看全部
舉報