[Numpy-discussion] Re: string matrices

Ryan Krauss ryanlists at gmail.com
Tue Apr 4 07:27:01 CDT 2006

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 [15]: temp[-2:]
Out[15]: '\x00\x00'

In [16]: temp.strip()
Out[16]: '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?  It would be slightly cleaner for me if the
string matrix elements didn't have the trailing null characters (or
whatever those are), but this may not be possible given the underlying



On 4/3/06, Ryan Krauss <ryanlists at gmail.com> wrote:
> I am trying to use NumPy to generate some matrix inputs to Maxima for
> symbolic analysis.  I am using a fair number of
> matrix.astype('S%d'%maxlen) statements.  This seems to work very well.
>  It also doesn't seem to pad the elements in anyway if maxlen is
> bigger than I need, which is great.  This may seem like a dumb
> computer science question, but what is the memory/performance cost of
> making maxlen bigger than I want (but making sure that it is way
> bigger than I need so that the elements don't get truncated)?  If my
> biggest matrices will be 13x13, how long can the strings be before I
> consume more than a few megs (or a few dozen megs) of memory?
> Thanks,
> Ryan

More information about the Numpy-discussion mailing list