Ndarray Min Max

Description

We can find the minimum and maximum value in an ndarray using the min and max commands.

Sage Cell

Code

import numpy as np
a = np.array([[2, 3, 5], [7, 11, 13]])
print a.min()
print a.max()

Options

Indices of min and max values

We can use the commands argmin and argmax to instead get the 1D index of the minimum and maximum values. This is the index of the item in a flattened array, or an array that has been turned into a 1D array.

Code

import numpy as np
a = np.array([[2, 3, 5], [7, 11, 13]])
print a.argmin()
print a.argmax()

Tags

Primary Tags:

Secondary Tags:

A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.

Related Cells

Any related cells go here. Provide a link to the page containing the information about the cell.

Attribute

Permalink:

Author:

Date: 08 Apr 2019 22:00

Submitted by: Zane Corbiere

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License