1、numpy.where()函数,此函数返回数组中满足某个条件的元素的索引:

import numpy as np

x = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print("x")
print(x)
y=np.where(x>5)
print(y)
print(x[y])

2、numpy.extract()函数,和where函数有一点相,不过extract函数是返回满足条件的元素,而不是元素索引,下面我们的例子返回数组x 的元素 模2等于0的元素。

condition=np.mod(x,2)==0
print(condition)
print(np.extract(condition,x))

 

相关文章:

  • 2022-12-23
  • 2022-01-20
  • 2022-02-17
  • 2021-12-17
  • 2021-11-16
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2021-11-26
  • 2021-05-11
  • 2021-08-19
相关资源
相似解决方案