j***@gmail.com
2015-09-04 14:11:13 UTC
I'm trying to build a meshgrid with small nonnegative integers
default is int32
If I use uint, then the arrays are upcast to int64 - Why?
dtype('int64')
broadcast_arrays preserves dtype
[array([[0, 0],
[1, 1],
[2, 2]], dtype=uint32), array([[0, 1],
[0, 1],
[0, 1]], dtype=uint32)]
with uint8
[array([[0, 0],
[1, 1],
[2, 2]], dtype=uint8), array([[0, 1],
[0, 1],
[0, 1]], dtype=uint8)]
dtype('int32')
Winpython 64 bit
Josef
default is int32
np.meshgrid([0,1,2], [0,1])[0].dtype
dtype('int32')If I use uint, then the arrays are upcast to int64 - Why?
np.meshgrid(np.array([0,1,2], np.uint), np.array([0,1],
np.uint))[0].dtypedtype('int64')
broadcast_arrays preserves dtype
np.broadcast_arrays(np.array([0,1,2], np.uint)[:,None], np.array([0,1],
np.uint)[None, :])[array([[0, 0],
[1, 1],
[2, 2]], dtype=uint32), array([[0, 1],
[0, 1],
[0, 1]], dtype=uint32)]
with uint8
np.broadcast_arrays(np.array([0,1,2], np.uint8)[:,None],
np.array([0,1], np.uint8)[None, :])[array([[0, 0],
[1, 1],
[2, 2]], dtype=uint8), array([[0, 1],
[0, 1],
[0, 1]], dtype=uint8)]
np.meshgrid(np.array([0,1,2], np.uint8), np.array([0,1],
np.uint8))[0].dtypedtype('int32')
Winpython 64 bit
np.__version__
'1.9.2rc1'Josef