On Thu, May 20, 2010 at 4:28 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
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.
for sure it doesn't look very consistent, special treatment of 0-dim ?
np.array(a[0], dtype=str) array('1', dtype='|S1') np.array(a[:1], dtype=str) array(['1'], dtype='|S4') a[:1].shape (1,) a[0].shape ()
Josef
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion