快速创建数组 python

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_43523725/article/details/102741622
arr = np.arange(0,5,0.1)
print(arr.shape) #(50,)

从数字0到数字5,步长为0.1创建一个一维数组,之后可以reshape,得到多维数组

arr1 = arr.reshape((10,5))
print(arr1)

输出结果为:

[[0.  0.1 0.2 0.3 0.4]
 [0.5 0.6 0.7 0.8 0.9]
 [1.  1.1 1.2 1.3 1.4]
 [1.5 1.6 1.7 1.8 1.9]
 [2.  2.1 2.2 2.3 2.4]
 [2.5 2.6 2.7 2.8 2.9]
 [3.  3.1 3.2 3.3 3.4]
 [3.5 3.6 3.7 3.8 3.9]
 [4.  4.1 4.2 4.3 4.4]
 [4.5 4.6 4.7 4.8 4.9]]

猜你喜欢

转载自blog.csdn.net/qq_43523725/article/details/102741622