You need an instance of the dtype
to get the itemsize, but you shouldn't need an instance of the ndarray
. (As will become clear in a second, nbytes
is a property of the array, not the dtype.)
E.g.
print np.dtype(float).itemsize
print np.dtype(np.float32).itemsize
print np.dtype('|S10').itemsize
As far as the difference between itemsize
and nbytes
, nbytes
is just x.itemsize * x.size
.
E.g.
In [16]: print np.arange(100).itemsize
8
In [17]: print np.arange(100).nbytes
800
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…