基础知识点汇总numpy -reshape,arange().reshape()

在这里插入代码片1、reshape函数生成的新数组和原始数组公用一个内存,也就是说,不管是改变新数组还是原始数组的元素,另一个数组也会随之改变
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
https://blog.csdn.net/qq_28618765/article/details/78083895
https://blog.csdn.net/lxlong89940101/article/details/84314703
才能使用 .reshape(c, -1) 函数, 表示将此矩阵或者数组重组,以 c行d列的形式表示(-1的作用就在此,自动计算d:d=数组或者矩阵里面所有的元素个数/c, d必须是整数,不然报错)(reshape(-1, e)即列数固定,行数需要计算):e就是几列
基础知识点汇总numpy -reshape,arange().reshape()_第1张图片基础知识点汇总numpy -reshape,arange().reshape()_第2张图片在这里插入图片描述
基础知识点汇总numpy -reshape,arange().reshape()_第3张图片基础知识点汇总numpy -reshape,arange().reshape()_第4张图片基础知识点汇总numpy -reshape,arange().reshape()_第5张图片
基础知识点汇总numpy -reshape,arange().reshape()_第6张图片

你可能感兴趣的:(基础知识点汇总numpy -reshape,arange().reshape())