Numpy 返回数组大小


import numpy as np

a = [[1, 2], [3, 4], [5, 6]]
b = np.array(a)
len(a)  # 3
len(b)  # 3
np.size(a)  # 3
np.size(a, 0)  # 3
np.size(a, 1)  # err
b.size  # 6
np.size(b)  # 6
np.size(b, 0)  # 3
np.size(b, 1)  # 2
np.shape(a)  # (3,)
b.shape  # (3, 2)
np.shape(b)  # (3, 2)
b.dtype  # dtype('int32')

c = [[1, 2], [3, 4], [5, 6, 7]]
d = np.array(c)
len(c)  # 3
len(d)  # 3
np.size(c)  # 3
np.size(c, 0)  # 3
np.size(c, 1)  # err
d.size  # 3
np.size(d)  # 3
np.size(d, 0)  # 3
np.size(d, 1)  # err
np.shape(c)  # (3,)
d.shape  # (3,)
np.shape(d)  # (3,)
d.dtype  # dtype('O')

 shape返回元组,size返回dtype的总数


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM