0

I am interested in sorting a matrix of type

a = array([[1,2,3],[4,5,6],[0,0,1]])

by some column as discussed here. One straight forward answer given there is

a[a[:,1].argsort()]

However, this seems to break the array in some cases as also commented there. In my case I start with a np.array of .shape (a,b). After the above code, I end up with an array of .shape (a,1,b). What are potential reasons for this behaviour?

Community
  • 1
  • 1
tomka
  • 2,516
  • 7
  • 31
  • 45
  • `a[a[:,1].argsort()].shape` from your example returns `(3,3)`. Numpy 1.11.0 – Dima Lituiev Oct 07 '16 at 22:50
  • @DimaLituiev Yes, I know. I can reproduce it too. But on another (large) matrix with different dimensions `a,b` I get shape `a,1,b`. I don't know what other information to give. – tomka Oct 07 '16 at 22:51
  • What is dimensionality of your matrix? What is dimensionality of `a[:,1].argsort()` for your matrix? – Dima Lituiev Oct 07 '16 at 22:52
  • @DimaLituiev Dimensionality of the matrix is `(10000, 784)`. Dimensionality of `a[:,1].argsort()` is `(10000, 1)`. – tomka Oct 07 '16 at 22:55
  • 1
    @DimaLituiev Following your comment: it seems `np.ravel(a[:,1].argsort())` solves the problem in my case. – tomka Oct 07 '16 at 22:59

0 Answers0