1

I'm trying to delete the arrays of this matrix:

https://mega.co.nz/#!wNo2Cb5T!0EoALVMtTJbC1-7dgFLbVK8deinL8tGK0eI68bRCOwo

I need delete only the arrays that have -1 in the last column, I tried this but doesn't work:

for i in range (m):
     if matriz[i][8]==-1:
     matriz=numpy.delete(matriz,i,0)

Any idea? :)

2
  • 1
    What do you mean: 'It doesn't work?'. Does it do nothing? Does it crash? Does it produce an adverse result? Commented Oct 25, 2014 at 12:49
  • The problem is that the output still have arrays with "-1" in the last column. Commented Oct 25, 2014 at 12:54

1 Answer 1

2

You actually shouldn't "delete" here, you should just use indexing:

good_rows = matriz[:,8] != -1
good_matriz = matrix[good_rows]

This will give you the rows where the 9th column is not -1, and it's more efficient than deleting one column at a time because it doesn't copy your data.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.