How do I remove all zero elements from a NumPy array?

前端 未结 6 463
逝去的感伤
逝去的感伤 2020-12-24 07:14

I have a rank-1 numpy.array of which I want to make a boxplot. However, I want to exclude all values equal to zero in the array. Currently, I solved this by loo

6条回答
  •  抹茶落季
    2020-12-24 07:37

    For a NumPy array a, you can use

    a[a != 0]
    

    to extract the values not equal to zero.

提交回复
热议问题