NumPy如何查找特定值的索引

  • NumPy如何查找特定值的索引

    要查找特定值的索引,可以使用np.where()函数。例如,要查找数组中值为5的索引,可以这样做:import numpy as nparr = np.array([1, 2, 3, 4, 5, 6])index = np.where(arr == 5)print(index)这将打印出值为5的索引,即array([4])。如果数组中有多个相同的值,np.where()将返回所有这些值的索引。

    2024-05-13
    0