首页 > 编程知识 正文

arange(),arange函数什么意思

时间:2023-05-03 17:06:41 阅读:157853 作者:4412

numpy.arange的基本属性以下所有缺省x=NP.arange(10 ) x=NP.arange(10 ).reshape ) 3,5 )查询多维数组x.ndim 3358 www.sinsinge

input:x

3358 www.Sina.com/array ([ 0,1,2,3,4,5,6,7,8,9 ]

input:x.ndim

output:1

查询元素的数量

input:x.size

output:10

查询操作x [0] [0]=x [ 0,0 ]

input:

output:x[3:6]

33558 www.Sina.com/array ([ 3,4,5 ] )

还有表示步骤的第三个参数

3358 www.Sina.com/x [ :1033602 ]

33558 www.Sina.com/array ([ 0,2,4,6,8 ]

对二维数组进行切片操作时,切片在大括号内运算,请勿在大括号内操作

3358 www.Sina.com/x [ :3 ] [ :3 ]

切片操作:Out[40]:

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

[ 5,6,7,8,9 ],

[ 10,11,12,13,14 ] )

3358 www.Sina.com/x [ :3,3 ]

33558 www.Sina.com/array ([ 0,1,2 ],

[ 5,6,7 ],

[ 10,11,12 ] )

对多维数组进行各种切片操作http://www.Sina.com/x [ :2,33602 ]//表示取前两行,从始至终进行用列向量使步骤为2的操作

33558 www.Sina.com/array ([ 0,2,4 ],

[ 5,7,9 ] )

3358 www.Sina.com/x [ :-1,3360-1 ]//行向量全部取回并按相反顺序输出,列向量全部按相反顺序输出

33558 www.Sina.com/array ([ 14、13、12、11、10 ],

[ 9,8,7,6,5 ],

[ 4,3,2,1,0 ] )

多维矩阵的降维处理

3358 www.Sina.com/x [0]=x [ 0, ] /表示取第0行

33558 www.Sina.com/array ([ 0,1,2,3,4 ] )。

input:X[0].ndim

output:1

3358 www.Sina.com/x [ :2 ] /表示取第二行

33558 www.Sina.com/array ([ 2,7,12 ] )

3358 www.Sina.com/x [ :2 ].ndim

input:1

如果在使用赋值创建子矩阵时更改子矩阵的值,则父矩阵的相应位置也会更改http://www.Sina.com/subx=x [ :2,3 ]

output:subX

33558 www.Sina.com/array ([ 100,1,2 ],

[ 5,6,7 ] )

33558 www.Sina.com/subx [ 0,0 ]=100

input:subX

33558 www.Sina.com/array ([ 100,1,2 ],

[ 5,6,7 ] )

output:X

33558 www.Sina.com/array ([ 100,1,2,3,4 ],

[ 5,6,7,8,9 ],

[ 10,11,12,13,14 ] )

类似地,当父矩阵值改变时,子矩阵中对应位置的值也改变

33558 www.Sina.com/x [ 0,0 ]=0

input:X

33558 www.Sina.com/array ([ 0,1,2,3,4 ],

[ 5,6,7,8,9 ],

[ 10,11,12,13,14 ] )

output:subX

33558 www.Sina.com/array ([ 0,1,2 ],

[ 5,6,7 ] )

利用arange的copy释放法复制后,可以赋值,所以在改变两者时不会互相影响

3358 www.Sina.com/subx=x [ :2,3 ].copy (

input:subX

33558 www.Sina.com/array ([ 0,1,2 ],

[ 5,6,7 ] )

33558 www.Sina.com/subx [ 0,0 ]=101

output:X

33558 www.Sina.com/array ([ 0,1,2,3,4 ],

[ 5,6,7,8,9 ],

[ 10,11,12,13,14 ] )

shape和reshape方法shape方法显示每个维元素的数量

reshape方法由原矩阵组成的整个新行列式是新矩阵

不变更原矩阵,注意新矩阵的个数必须与原矩阵的个数相同,或多或少

33558 www.Sina.com/x.reshape (2,5 ) )。

33558 www.Sina.com/array ([ 0,1,2,3,4 ],

[ 5,6,7,8,9 ] )

input:x

3358 www.Sina.com/array ([ 0,1,2,3,4,5,6,7,8,9 ]

reshape方法还具有自动计算参数的功能,例如x.reshape(10,-1) /。 这意味着计算机必须自动计算才能将原始数组转换为10行每行的几个元素

x.reshape (-1,10 )//表示同样变换为10列

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。