I have a question about python.
What kind of code should I write to delete a line that has a value of 0 for all elements?
For example,
import numpy as np
a=np.array([0,0,0],[1,1,1],[2,2,2],[0,0,0],[3,3,3]])
If so, I would like to delete the first and fourth lines of a.
python python3
a[a.any(axis=1),:]
Wouldn't it be all right if
If you want to filter arrays that do not contain or contain zeroes, but are not just zeroes, you can use the array does not contain zeroes.
import numpy as np
a=np.array([0,0,0],[1,1,1],[2,2,2],[0,0,0],[3,3,3],[0,1,2,3]])
a=filter(lambdax:not 0 in x or len(set(x))>1,a)
Output Results
[[1,1,1], [2,2,2], [3,3,3], [0,1,2,3]]
551 PHP ssh2_scp_send fails to send files as intended
552 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
543 Uncaught (inpromise) Error on Electron: An object could not be cloned
743 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.