
On Thu, May 20, 2010 at 1:19 PM, josef.pktd@gmail.com wrote:
On Thu, May 20, 2010 at 4:04 PM, Keith Goodman kwgoodman@gmail.com wrote:
Why do the follow expressions give different dtype?
np.array([1, 2, 3], dtype=str)
array(['1', '2', '3'], dtype='|S1')
np.array(np.array([1, 2, 3]), dtype=str)
array(['1', '2', '3'], dtype='|S8')
you're on a 64bit machine?
S8 is the same size as the float
np.array([8]).itemsize
4
np.array(np.array([1, 2, 3]), dtype=str)
array(['1', '2', '3'], dtype='|S4')
np.array([8]).view(dtype='S4')
array(['\x08'], dtype='|S4')
np.array([8]).view(dtype='S1')
array(['\x08', '', '', ''], dtype='|S1')
But I don't know whether this is a desired feature, numpy might reuse the existing buffer (?)
Yes, I'm on a 64-bit machine.
That's what I thought so I tried this:
a = np.array([1, 2, 3]) type(a[0])
<type 'numpy.int64'>
np.array([a[0], a[1], a[2]], dtype=str)
array(['1', '2', '3'], dtype='|S1')
But it gives '|S1' too. I guess I'm lost.