0

I want to remove all row that is all zero. I followed this question (as well as this) and tried the code directly in cmd, it worked well. But when I run the code from the file in cmd >python myfile.py, it does not work.

The code is only

import numpy as np
aaa = np.zeros(shape=(2,4))
print aaa
aaa[~np.all(aaa == 0, axis=1)]
print aaa

Nothing is removed. I got exactly same array between two print. Why is it not working via the file?

Community
  • 1
  • 1
Jan
  • 1,389
  • 4
  • 17
  • 43

1 Answers1

4

That's because you're not updating aaa:

aaa = aaa[~np.all(aaa == 0, axis=1)]

It "works" in your terminal since the evaluation of that expression is printed to the terminal

Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139