0

I am new to python and I want to implement the algorithm in matlab using python as i found the solution from here: Numpy vs mldivide,"\" matlab operator

When I print the shape of the sol variable I got:

(3, 1) (3, 1) (3, 1)

Here is the answer of sol variable:

[[-1. ]
 [ 4.5]
 [ 0. ]]

[[ 8.]
 [ 0.]
 [ 6.]]

[[ 0.        ]
 [ 4.        ]
 [ 0.66666667]] 

My desire answer:

[[ 0.        ]
 [ 4.        ]
 [ 0.66666667]]

How can I select the last numpy-array as it is the solution I need as it is the solution of matlab. Thanks before hand!

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Erwin
  • 325
  • 1
  • 9

1 Answers1

0

This is pretty straightforward as follows:

>>> arr = np.arange(9).reshape(3,3)
>>> arr
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])
>>> arr[2::]
array([[6, 7, 8]])

OR

>>> arr[-1::]
array([[6, 7, 8]])
Aaj Kaal
  • 1,205
  • 1
  • 9
  • 8