>
> > That says, "This is a 0-length array of 3-char Unicode strings." Numpy
> > doesn't recognize the string as a specification of an array. Try
> > `np.array(4.)` and you'll get (IIRC) `array(4., dtype='float')`, which
> > has
> > shape `()`. Numpy probably won't let you index either one. What can you
> > even do with it?
>
> In my poking around I found that you can index it with [()] or access
> with .item() and .itemset(value). Still seems more like a party trick
> than the well-reasoned practical implementation choice he implied it
> was.


my apologies about the confusion, the dim=() was not the point, but rather
that numpy treats the string as a monolithic object rather than
disassembling it as it would do with other iterables.  I was just trying to
give the simplest possible example.

Numpy still does

>>> np.array([[1,2],[3,4]])
array([[1, 2],
       [3, 4]])
>>> np.array([[1,2],[3,4]]).shape
(2, 2)

but not here

>>> np.array(['ab','cd'])
array(['ab', 'cd'],
      dtype='<U2')
>>> np.array(['ab','cd']).shape
(2,)

-Alexander
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to