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())
Related Posts:
- numpy array: IndexError: too many indices for array
- Python3 – ModuleNotFoundError: No module named ‘numpy’
- ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
- Curve curvature in numpy
- How can I prevent the TypeError: list indices must be integers, not tuple when copying a python list to a numpy array?
- Converting NumPy array into Python List structure?
- The difference between comparison to np.nan and isnull()
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- Is there a way to create multiline comments in Python?
- How to update/upgrade a package using pip?
- How can I remove a specific item from an array?
- How do I update\upgrade pip itself from inside my virtual environment?
- IndexError: too many indices for array
- Import Error: No module named numpy
- How do I specify new lines on Python, when writing on files?
- What is the purpose of the return statement?
- bash: pip: command not found
- How do I check what version of Python is running my script?
- Converting integer to string in Python
- deleting file if it exists; python
- Reverse a string in Python
- Python for-in loop preceded by a variable
- Python Linked List
- What does if __name__ == “__main__”: do?
- How to print without a newline or space
- Error: ‘int’ object is not subscriptable – Python
- How to measure elapsed time in Python?
- How to uninstall Anaconda completely from macOS
- Python: Start and stop timer [duplicate]
- Does Python have a ternary conditional operator?
- not all arguments converted during string formatting.. NO % variables
- How do I install opencv using pip?
- TypeError: ‘builtin_function_or_method’ object is not subscriptable
- How do I compare two strings in python?
- numpy max vs amax vs maximum
- ImportError: No module named sklearn.cross_validation
- Converting string into datetime
- ImportError: No module named matplotlib.pyplot
- How do I list all files of a directory?
- What is the purpose of meshgrid in Python / NumPy?
- why numpy.ndarray is object is not callable in my simple for python loop
- numpy division with RuntimeWarning: invalid value encountered in double_scalars
- How do I create an empty array/matrix in NumPy?
- Most efficient way to find mode in numpy array
- numpy matrix vector multiplication
- How do I read CSV data into a record array in NumPy?
- How do I read CSV data into a record array in NumPy?
- How to normalize a NumPy array to a unit vector?
- ImportError: numpy.core.multiarray failed to import
- ImportError: numpy.core.multiarray failed to import
- numpy array concatenate: “ValueError: all the input arrays must have same number of dimensions”
- ‘DataFrame’ object has no attribute ‘sort’
- convert nan value to zero
- Most efficient way to map function over numpy array
- Is there a NumPy function to return the first index of something in an array?
- Numpy/Python Array Value error
- TypeError: ‘DataFrame’ object is not callable
- LinAlgError: Last 2 dimensions of the array must be square
- What does axis in pandas mean?
- Python: slicing a multi-dimensional array
- How to implement the Softmax function in Python
- Add single element to array in numpy
- 3-dimensional array in numpy
- How do you get the magnitude of a vector in Numpy?
- ‘list’ object has no attribute ‘shape’
- What is the difference between np.mean and tf.reduce_mean?
- How to calculate rolling / moving average using python + NumPy / SciPy?
- ValueError: object too deep for desired array while using convolution
- Make list of arrays in python
- Import Error: No module named numpy Anaconda
- What does ‘index 0 is out of bounds for axis 0 with size 0’ mean?
- pandas create new column based on values from other columns / apply a function of multiple columns, row-wise
- Moving average or running mean
- ValueError: x and y must be the same size
- NumPy List Comprehension Syntax
- Linear regression with matplotlib / numpy
- How to get the unit vector from a numpy array
- Numpy float64 vs Python float
- “Divide by zero encountered in log” when not dividing by zero
- RuntimeError: module compiled against API version a but this version of numpy is 9
- Good ways to “expand” a numpy ndarray?
- urllib2.HTTPError: HTTP Error 403: Forbidden
- TypeError: ‘numpy.float64’ object does not support item assignment
- Python/Django: log to console under runserver, log to file under Apache
- numpy-equivalent of list.pop?
- Efficiently sorting a numpy array in descending order?
- How to add column to numpy array
- How to fix ‘RuntimeWarning: divide by zero encountered in double_scalars’
- IndexError: index 2 is out of bounds for axis 0 with size 2
- Coalesce values from 2 columns into a single column in a pandas dataframe
- Compute a confidence interval from sample data
- Create numpy matrix filled with NaNs
- How do I compute derivative using Numpy?
- ImportError: cannot import name NUMPY_MKL
- built-in range or numpy.arange: which is more efficient?
- Convert a 1D array to a 2D array in numpy
- inverting image in Python with OpenCV
- How to print the full NumPy array, without truncation?
- Calculate weighted average using a pandas/dataframe
- TypeError: zip argument #2 must support iteration