numpy.ndarray.T doesn't change the structure?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

numpy.ndarray.T doesn't change the structure?

m.meliani
This post has NOT been accepted by the mailing list yet.
 Hello,

 I've come across something very odd using NumPy. In the following lines I
 use numpy.ndarray.T, but it seems it doesn't change the structure of the
 data only the way they're displayed. Which was a problem for what I wanted
 to do (I changed my approach since and was able to do what I wanted:
 sorting the 2-D array a certain way). But still I found it very curious
 since the shape, the type and dtype of both arrays are the same. Does anyone
 have any idea what's happening?

  >>> import numpy as np
  >>> x=np.array([[0,1,2],[1,2,3]])
  >>> x=x.T
  >>> print x
  [[0 1]
   [1 2]
   [2 3]]
  >>> y=np.array([[0,1],[1,2],[2,3]])
  >>> print y
  [[0 1]
   [1 2]
   [2 3]]
  >>> y.view('i8,i8')
  array([[(0, 1)],
         [(1, 2)],
         [(2, 3)]],
        dtype=[('f0', '<i8'), ('f1', '&lt;i8')])
  >>> x.view('i8,i8')
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  ValueError: new type not compatible with array.


 PS: an x.view("i8,i8,i8") works  and y.view("i8,i8,i8") doesn't .
Loading...