目录
shape属性
size属性
动态调正
动态创建连续数组
ndim属性
itemsize属性
首先生成个数组
import numpy as np a = np.array([[1,2,3],[4,5,6]]) print(a)结果输出:
array([[1, 2, 3],[4, 5, 6]])结果输出:
(2, 3)结果输出:
6结果输出:
array([[1, 2], [3, 4], [5, 6]]) newa.reshape(1,6) #动态调整维度 print(newa)结果输出:
array([[1, 2, 3, 4, 5, 6]])结果输出:
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]) print(makea.reshape(4,6)) #不会改变的原来的结果输出:
array([[ 0, 1, 2, 3, 4, 5], [ 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17], [18, 19, 20, 21, 22, 23]] makea=makea.reshape(3,8) print(makea)结果输出:
array([[ 0, 1, 2, 3, 4, 5, 6, 7], [ 8, 9, 10, 11, 12, 13, 14, 15], [16, 17, 18, 19, 20, 21, 22, 23]])结果输出:
2结果输出:
array([[[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]], [[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]]]) print(makea.itemsize) #这一数组属性返回数组中每个元素的字节单位长度。结果输出:
4