python中numpy的知识点总结Word文件下载.docx

上传人:b****5 文档编号:18614246 上传时间:2022-12-29 格式:DOCX 页数:8 大小:15.77KB
下载 相关 举报
python中numpy的知识点总结Word文件下载.docx_第1页
第1页 / 共8页
python中numpy的知识点总结Word文件下载.docx_第2页
第2页 / 共8页
python中numpy的知识点总结Word文件下载.docx_第3页
第3页 / 共8页
python中numpy的知识点总结Word文件下载.docx_第4页
第4页 / 共8页
python中numpy的知识点总结Word文件下载.docx_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

python中numpy的知识点总结Word文件下载.docx

《python中numpy的知识点总结Word文件下载.docx》由会员分享,可在线阅读,更多相关《python中numpy的知识点总结Word文件下载.docx(8页珍藏版)》请在冰豆网上搜索。

python中numpy的知识点总结Word文件下载.docx

Out[6]:

array([1,2])

np.sum(x<

3)

Out[7]:

2

y=np.array([[1,2,3,4,5],[6,7,8,9,10]])

y

Out[8]:

array([[1, 

2, 

3, 

4, 

5],

 

[6, 

7, 

8, 

9,10]])

x==y[0,]

Out[9]:

True, 

#两个数组比较

a1=np.arange(9).reshape(3,3)

a2=np.arange(9,0,-1).reshape(3,3)

a1<

a2

Out[10]:

array([[True, 

True],

[True, 

True,False],

[False,False,False]])

#####数据的切片选择(开始位,结束位,步长)

#位置值从0开始的

x=np.arange(0,10)

x[4:

6]

Out[11]:

array([4,5])

#从0开始,步长为2的数据,:

:

表示所有数据

x[:

2]

Out[12]:

array([0,2,4,6,8])

#倒序

-1]

Out[13]:

array([9,8,7,6,5,4,3,2,1,0])

#取前6个数据

Out[14]:

array([0,1,2,3,4,5])

#从第2的位置开始选

x[2:

]

Out[15]:

array([2,3,4,5,6,7,8,9])

#二维数据的切片处理,生成0-15的数字,4行4列

y=np.arange(0,16).reshape(4,4)

Out[16]:

array([[0, 

1, 

3],

[4, 

5, 

6, 

7],

[8, 

9,10,11],

[12,13,14,15]])

#y[行,列],取所有行和第二列与第三列

y[:

1:

3]

Out[17]:

2],

[5, 

6],

[9,10],

[13,14]])

y[1:

3,2:

4]

Out[18]:

array([[6, 

[10,11]])

#y[:

:

]中的:

表示取所有

y[[1,3],:

Out[19]:

array([[4, 

####数据的维度变化#####

x=np.arange(0,9)

y=x.reshape(3,3)

Out[20]:

array([[0,1,2],

[3,4,5],

[6,7,8]])

Out[21]:

#返回一个新的数组,不是修改原来的数组

y.reshape(9)

Out[22]:

array([0,1,2,3,4,5,6,7,8])

Out[23]:

#修改数据

reshaped=y.reshape(np.size(y))

raveled=y.ravel()#将数据展开成一维的

reshaped[2]=1000

raveled[5]=2000

Out[24]:

array([[ 

0, 

1,1000],

3, 

4,2000],

6, 

8]])

y=np.arange(0,9).reshape(3,3)

flattened=y.flatten()#将数据展开成一维的

flattened[0]=1000

flattened

Out[25]:

array([1000, 

8])

flattened.shape=(3,3)

Out[26]:

array([[1000, 

#数据的转置

flattened.T

Out[27]:

1, 

2, 

####数据的合并处理####

a=np.arange(9).reshape(3,3)

b=(a+1)*10

a

Out[28]:

b

Out[29]:

array([[10,20,30],

[40,50,60],

[70,80,90]])

#水平方向

np.hstack((a,b))

Out[30]:

2,10,20,30],

[3, 

5,40,50,60],

8,70,80,90]])

#垂直方向

np.vstack((a,b))

Out[31]:

8],

[10,20,30],

#axis=1横轴方向,axis=0竖轴方向

np.concatenate((a,b),axis=1)

Out[32]:

#每列相互拼接

np.dstack((a,b))

Out[33]:

array([[[0,10],

[1,20],

[2,30]],

[[3,40],

[4,50],

[5,60]],

[[6,70],

[7,80],

[8,90]]])

#两列拼接

one_d_a=np.arange(5)

one_d_b=(one_d_a+1)*10

np.column_stack((one_d_a,one_d_b))

Out[36]:

array([[0,10],

[1,20],

[2,30],

[3,40],

[4,50]])

##行叠加

np.row_stack((one_d_a,one_d_b))

Out[37]:

4],

[10,20,30,40,50]])

####通用函数####

m=np.arange(10,19).reshape(3,3)

print(m)

print("

{0}minoftheentirematrix"

.format(m.min()))

{0}maxofentirematrix"

.format(m.max()))

##最小值、最大值的位置

{0}positionoftheminvalue"

.format(m.argmin()))

{0}positionofthemaxvalue"

.format(m.argmax()))

#每列、每行的最小值

{0}minsdowneachcolumn"

.format(m.min(axis=0)))

{0}minsacrosseachrow"

.format(m.min(axis=1)))

#每列、每行的最大值

{0}maxsdowneachcolumn"

.format(m.max(axis=0)))

{0}maxsacrosseachrow"

.format(m.max(axis=1)))

[[101112]

[131415]

[161718]]

10minoftheentirematrix

18maxofentirematrix

0positionoftheminvalue

8positionofthemaxvalue

[101112]minsdowneachcolumn

[101316]minsacrosseachrow

[161718]maxsdowneachcolumn

[121518]maxsacrosseachrow

#平均值,标准差,方差

Out[41]:

array([1,2,3,4,5,6,7,8,9])

a=np.arange(1,10)

a.mean(),a.std(),a.var()

Out[39]:

(5.0,2.581988897471611,6.666666666666667)

#求和,乘积

a.sum(),a.prod()

Out[40]:

(45,362880)

#累加和,累加乘

a.cumsum(),a.cumprod()

Out[42]:

(array([1, 

6,10,15,21,28,36,45],dtype=int32),

array([ 

24, 

120, 

720, 

5040, 

40320,

362880],dtype=int32))

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 成人教育 > 成考

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1