[Numpy-discussion] Re: string matrices
oliphant.travis at ieee.org
Tue Apr 4 11:25:11 CDT 2006
Ryan Krauss wrote:
> I actually have a problem with the elements of a string matrix from
> astype('S#'). The shorter elements in my matrix have a bunch of terms
> like '1.0', because the matrix they started from was a float. I need
> to keep the float type, but want to get rid of the '.0 ' when I
> convert the string output to latex. I was going to check if
> element[-2:]=='.0' but ran into this problem
> In : temp[-2:]
> Out: '\x00\x00'
> In : temp.strip()
> Out: '1.0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
> I think I can get rid of the \x00's by calling str(element), but is
> this a feature or a bug?
Of course the elements are padded with '\x00' so that they are all the
same length, but we have been trying to make it so that it doesn't
matter. Equality testing is one area where it still does. We are
using the underlying string equality testing (and it doesn't strip the
'\x00'). So, I guess it's a missing feature at this point.
More information about the Numpy-discussion