numpy生成数组
导包import numpy as np
随机生成数组
随机生成维度大小为3*4*5的数组
nd1=np.random.rand(3,4,5)
print(nd1)
print(type(nd1))
维度(dimension)个数
print('nd1.ndim)
维度大小
print(nd1.shape)
维度数据类型
print(nd1.dtype)
输出结果
随机生成指定数据范围的数组
生成一个数据范围为[0,2)的数组,维度大小为1
nd2=np.random.uniform(2)
print(nd2)
print(type(nd2))
print('###########')
生成一个维度范围为[2,3)的数组,维度大小为1
nd3=np.random.uniform(2,3)
print(nd3)
print(type(nd3))
print('###############')
生成一个维度范围为[-1,5)的数组,维度大小为2*3
nd4=np.random.uniform(-1,5,size=(2,3))
print(nd4)
print(type(nd4))
print(nd4.shape)
print(nd4.ndim)
print(nd4.dtype)
print('###############')