'numpy.ndarray' object has no attribute 'index'
First of all, index
is a list method. Here v
is a numpy array and you need to do the following:
v = np.random.randn(10)
print(v)
maximum = np.max(v)
minimum = np.min(v)
print(maximum, minimum)
index_of_maximum = np.where(v == maximum)
index_of_minimum = np.where(v == minimum)
Get the elements using these indices:
v[index_of_minimum]
v[index_of_maximum]
Verify using assert:
assert(v[index_of_maximum] == v.max())
assert(v[index_of_minimum] == v.min())
If you are using Numpy:
values = np.array([3,6,1,5])
index_min = np.argmin(values)
print(index_min)
returns the index of 2.