[Numpy-discussion] Array resize question

Cristi Constantin darkgl0w@yahoo....
Tue Jun 16 09:42:35 CDT 2009


Good day.
I have this array:

a = array([[u'0', u'0', u'0', u'0', u'0', u' '],
       [u'1', u'1', u'1', u'1', u'1', u' '],
       [u'2', u'2', u'2', u'2', u'2', u' '],
       [u'3', u'3', u'3', u'3', u'3', u' '],
       [u'4', u'4', u'4', u'4', u'4', u'']], 
      dtype='<U1')

I want to resize it, but i don't want to alter the order of elements.

a.resize((5,10)) # Will result in
array([[u'0', u'0', u'0', u'0', u'0', u' ', u'1', u'1', u'1', u'1'],
       [u'1', u' ', u'2', u'2', u'2', u'2', u'2', u' ', u'3', u'3'],
       [u'3', u'3', u'3', u' ', u'4', u'4', u'4', u'4', u'4', u''],
       [u'', u'', u'', u'', u'', u'', u'', u'', u'', u''],
       [u'', u'', u'', u'', u'', u'', u'', u'', u'', u'']], 
      dtype='<U1')

That means all my values are mutilated. What i want is the order to be kept and only the last elements to become empty. Like this:
array([[u'0', u'0', u'0', u'0', u'0', u' ', u'', u'', u'', u''],

       [u'1', u'1', u'1', u'1', u'1', u' ', u'', u'', u'', u''],

       [u'2', u'2', u'2', u'2', u'2', u' ', u'', u'', u'', u''],

       [u'3', u'3', u'3', u'3', u'3', u' ', u'', u'', u'', u''],

       [u'4', u'4', u'4', u'4', u'4', u' ', u'', u'', u'', u'']], 

      dtype='<U1')


I tried to play with resize like this:
a.resize((5,10), refcheck=True, order=False)
# SystemError: NULL result without error in PyObject_Call

vCont1.resize((5,10),True,False)
# TypeError: an integer is required

Can anyone tell me how this "resize" function works ?
I already checked the help file : http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.resize.html
Thank you in advance.




      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090616/851f98db/attachment.html 


More information about the Numpy-discussion mailing list