import numpy as np
a=[2,10,2,3,4,10,10]
ans = np.where(np.array(a)==10)
print(ans)

结果是:(array([1, 5, 6], dtype=int64),)

就是说,np.where()可以返回同一个元素在不同位置的索引。

a=[2,10,2,3,4,10,10]
ans = a.index(10)
print(ans)

结果是:1

就是说,a.index()返回指定元素第一个位置的索引。

 

相关文章:

  • 2021-07-05
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2022-12-23
  • 2021-10-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2021-06-06
相关资源
相似解决方案