Python中的shape和reshape()
生活随笔
收集整理的這篇文章主要介紹了
Python中的shape和reshape()
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
shape是查看數(shù)據(jù)有多少行多少列
reshape()是數(shù)組array中的方法,作用是將數(shù)據(jù)重新組織
shape
import numpy as np a = np.array([1,2,3,4,5,6,7,8]) #一維數(shù)組 print(a.shape[0]) #值為8,因為有8個數(shù)據(jù) print(a.shape[1]) #IndexError: tuple index out of rangea = np.array([[1,2,3,4],[5,6,7,8]]) #二維數(shù)組 print(a.shape[0]) #值為2,最外層矩陣有2個元素,2個元素還是矩陣。 print(a.shape[1]) #值為4,內層矩陣有4個元素。 print(a.shape[2]) #IndexError: tuple index out of range?
reshape()
reshape新生成數(shù)組和原數(shù)組公用一個內存,不管改變哪個都會互相影響。
?
原文地址:https://blog.csdn.net/u010916338/article/details/84066369
總結
以上是生活随笔為你收集整理的Python中的shape和reshape()的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: centos7下kafka2.12-2.
- 下一篇: 抛开flash,自己开发实现C++ RT