The program organizes is done to organize the rows, based on the value of the third column, I did the program and it worked, but when I use numpy array, it gives the error below. I need to use numpy array because it's part of a larger program that I'm using numpy.
import numpy as np
y = np.matrix([[-1,1,4],[2,-2,7],[10,7,1]])
c = True
def OrdenaMatriz(y):
matriz = []
matriz.append(y[0])
for a in range(2):
if y[a,2] < y[a+1,2]:
matriz.insert(a,y[a+1])
else:
matriz.append(y[a+1])
return matriz
while c == True:
a = OrdenaMatriz(y)
if a == y:
c = False
print(a)
y = a
ERROR THAT YOU ARE GIVING:
DeprecationWarning: elementwise == comparison failed; this will raise an
error in the future.
if a == y:
Traceback (most recent call last):
File "teste.py", line 26, in <module>
a = OrdenaMatriz(y)
File "teste.py", line 19, in OrdenaMatriz
if y[a,2] < y[a+1,2]:
TypeError: list indices must be integers or slices, not tuple