shape:查看数据有多少行多少列
reshape():重组array的函数
1. shape
import numpy as np
a = np.array([1,2,3,4,5,6,7,8]) #一维数组
print(a.shape[0]) #值为8,因为有8个数据
print(a.shape[1]) #IndexError: tuple index out of range
a = np.array([[1,2,3,4],[5,6,7,8]]) #二维数组
print(a.shape[0]) #值为2,最外层矩阵有2个元素,2个元素还是矩阵。
print(a.shape[1]) #值为4,内层矩阵有4个元素。
print(a.shape[2]) #IndexError: tuple index out of range
2. reshape()

reshape新生成数组和原数组公用一个内存,不管改变哪个都会互相影响。

参考:
[1] https://blog.youkuaiyun.com/u010916338/article/details/84066369
本文介绍了NumPy中数组的shape属性,用于查看数组的维度信息,如行数和列数。同时,详细讲解了reshape()函数的使用,该函数可以重新组织数组的形状,但需注意新数组与原数组共享同一内存空间,修改任一方将影响另一方。
2681

被折叠的 条评论
为什么被折叠?



