[Numpy-discussion] Empty strings not empty?
Tue Dec 29 20:36:25 CST 2009
On Wed, Dec 30, 2009 at 10:20 AM, Matthew Brett <firstname.lastname@example.org> wrote:
>> x = "¥00"
>> arr = np.array([x])
>> lst = [x]
>> arr == x # False
>> arr == "" # True
>> lst == x # True
>> lst == "" # False
> Ah - thanks - got it.
>>> It looks to me as though the
>>> buffer contents of [''] is a length 1 string with a 0 byte, and an
>>> array.size of 1 - is that also what you think? I guess I think that
>>> it should be a length 0 string, with a array.size of 0
>> Array size of 0 would be very weird: it means it would have no items,
>> whereas it actually has one item (which itself has a size 0).
> Is this a string-specific thing?
No. I was not very clear: My point was that size 0 array is likely not
what you want. What you want is arrays whose *itemsize" is 0.
> I mean, you can have size 0 1d
> numeric arrays. Sorry if I'm being slow, it's late here.
> In : np.array([]).shape
> Out: (1, 0)
> In : np.array([]).size
> Out: 0
Yes, you can create array with size 0. But I don't think that's what
you want - you cannot index them normally (even though the array is
2d, you cannot do arr, so I don't think that's very useful for
More information about the NumPy-Discussion