(2,3)
,该属性可以用来调整数组维度的大小。import numpy as np a = np.array([[2,4,6],[3,5,7]]) print(a.shape)输出结果:
(2,3)
通过 shape 属性修改数组的形状大小:import numpy as np a = np.array([[1,2,3],[4,5,6]]) a.shape = (3,2) print(a)输出结果:
[[1, 2] [3, 4] [5, 6]]
import numpy as np a = np.array([[1,2,3],[4,5,6]]) b = a.reshape(3,2) print(b)输出结果:
[[1, 2] [3, 4] [5, 6]]
import numpy as np #随机生成一个一维数组 c = np.arange(24) print(c) print(c.ndim) #对数组进行变维操作 e = c.reshape(2,4,3) print(e) print(e.ndim)输出结果如下所示:
#随机生成的c数组 [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23] #c数组的维度 1 #变维后数组e [[[ 0 1 2] [ 3 4 5] [ 6 7 8] [ 9 10 11]] [[12 13 14] [15 16 17] [18 19 20] [21 22 23]]] #e的数组维度 3
#数据类型为int8,代表1字节 import numpy as np x = np.array([1,2,3,4,5], dtype = np.int8) print (x.itemsize)输出结果为:
1
#数据类型为int64,代表8字节 import numpy as np x = np.array([1,2,3,4,5], dtype = np.int64) print (x.itemsize)输出结果:
8
import numpy as np x = np.array([1,2,3,4,5]) print (x.flags)输出结果如下:
C_CONTIGUOUS : True F_CONTIGUOUS : True OWNDATA : True WRITEABLE : True ALIGNED : True WRITEBACKIFCOPY : False UPDATEIFCOPY : False
本文链接:http://task.lmcjl.com/news/13591.html