Hi,
On Thu, Dec 31, 2009 at 2:08 AM, Christopher Barker
chris.bar...@noaa.gov wrote:
Charles R Harris wrote:
That is due to type promotion for the ufunc call:
In [17]: a1 = np.array('a\x00\x00\x00')
n [21]: np.array(['a'], dtype=a1.dtype)[0]
Out[21]: 'a'
In [22]: np.array(['a'],
Matthew Brett wrote:
I think the summary here is 'numpy strings are zero padded; therefore
you may run into surprises with a string that has trailing zeros'.
I see why that is - the zero terminator is the only way for numpy
arrays to see where the end of the string is...
almost -- it's not
On Tue, Dec 29, 2009 at 4:35 PM, Matthew Brett matthew.br...@gmail.comwrote:
Hi,
I was surprised by this - should I have been?
In [35]: e = np.array(['a'])
In [36]: e.shape
Out[36]: (1,)
In [37]: e.size
Out[37]: 1
In [38]: e.tostring()
Out[38]: 'a'
In [39]: f = np.array(['a'])
Hi.
It isn't empty:
In [3]: array(['\x00']).dtype
Out[3]: dtype('|S1')
In [4]: array(['\x00']).tostring()
Out[4]: '\x00'
In [5]: array(['\x00'])[0]
Out[5]: ''
No, but my problem was that an empty string is not empty either, and
that you can't therefore distinguish between an empty
On Wed, Dec 30, 2009 at 12:00 PM, Matthew Brett matthew.br...@gmail.comwrote:
Hi.
It isn't empty:
In [3]: array(['\x00']).dtype
Out[3]: dtype('|S1')
In [4]: array(['\x00']).tostring()
Out[4]: '\x00'
In [5]: array(['\x00'])[0]
Out[5]: ''
No, but my problem was that an empty
Charles R Harris wrote:
That is due to type promotion for the ufunc call:
In [17]: a1 = np.array('a\x00\x00\x00')
n [21]: np.array(['a'], dtype=a1.dtype)[0]
Out[21]: 'a'
In [22]: np.array(['a'], dtype=a1.dtype).tostring()
Out[22]: 'a\x00\x00\x00'
it took me a bit to figure out what
On Wed, Dec 30, 2009 at 8:35 AM, Matthew Brett matthew.br...@gmail.com wrote:
Hi,
I was surprised by this - should I have been?
In [35]: e = np.array(['a'])
In [36]: e.shape
Out[36]: (1,)
In [37]: e.size
Out[37]: 1
In [38]: e.tostring()
Out[38]: 'a'
In [39]: f = np.array(['a'])
Hmmm... I don't see where you created an empty string array in your
examples. All three of your arrays contain one element, so they are not
empty. The element in the array z happens to be zero, is all.
Here's an example of creating an empty string array:
In [2]: e = np.array([],dtype='S')
Hi,
I don't see any empty string in your code ? They all have one byte.
The last one is slightly confusing as far as printing is concerned (I
would have expected array([¥x00]...) instead). It may be a bug in
numpy because a byte with value 0 is used a string delimiter in C.
Sorry - I pasted
On Wed, Dec 30, 2009 at 8:52 AM, Matthew Brett matthew.br...@gmail.com wrote:
In [58]: e == z
Out[58]: array([ True], dtype=bool)
Ok, it looks like there are at least two issues:
- if an item in a string array is set to '¥x00', this seems to be
replace with '', but '' != '¥x00']
x =
Hi,
Ok, it looks like there are at least two issues:
- if an item in a string array is set to '¥x00', this seems to be
replace with '', but '' != '¥x00']
Sorry - I'm afraid I don't understand. It looks to me as though the
buffer contents of [''] is a length 1 string with a 0 byte, and an
Hi,
x = ¥00
arr = np.array([x])
lst = [x]
arr[0] == x # False
arr[0] == # True
lst[0] == x # True
lst[0] == # 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?
On Wed, Dec 30, 2009 at 10:20 AM, Matthew Brett matthew.br...@gmail.com wrote:
Hi,
x = ¥00
arr = np.array([x])
lst = [x]
arr[0] == x # False
arr[0] == # True
lst[0] == x # True
lst[0] == # False
Ah - thanks - got it.
It looks to me as though the
buffer contents of [''] is a
13 matches
Mail list logo