python中size、shape、len的區別


size計算矩陣中所有元素的個數;
.shape返回維度值,返回一個元組
len()可以想象成數據長度/條數,即數據的行數
輸入:

a = np.array([[1, 2, 3, 4], [1, 2, 3, 4]])
print(len(a))
print(a.size)
print(a.shape)

輸出:

2
8
(2, 4)

參考博客(侵刪):
https://blog.csdn.net/peggiehu/article/details/107004480
https://blog.csdn.net/chen_swith/article/details/107633829?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-2&spm=1001.2101.3001.4242


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM