Trusted answers to developer questions

Umme Ammara

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Python’s ** numpy.fmin()** computes the element-wise minimum of an array. It compares two arrays and returns a new array containing the minimum values.

The difference between the

`fmin()`

and`minimum()`

functions in numpy is that the`fmin()`

function ignores`NaN`

values whereas the`minimum()`

function propagates`NaN`

values.

`numpy.fmin()`

is declared as follows:

```
numpy.fmin(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'fmin'>
```

In the syntax given above, `x1`

and `x2`

are non-optional parameters, and the rest are optional parameters.

A universal function (ufunc) is a function that operates on ndarrays in an element-by-element fashion. The

`fmin()`

method is a universal function.

The `numpy.fmin()`

method takes the following compulsory parameters:

and`x1`

[`x2`

*array-like*] - arrays holding the values that need to be compared. If the ofshape the shape of an array is the number of elements in each dimension `x1`

and`x2`

is different, they must be broadcastable to a common shape for representing the output.

The `numpy.fmin()`

method takes the following optional parameters:

Parameter | Description |

out | represents the location into which the output of the method is stored |

where | True value indicates that a universal function should be calculated at this position |

casting | controls the type of datacasting that should occur. The |

order | controls the memory layout order of the output function. The option |

dtype | represents the desired data type of the array |

subok | decides if subclasses should be made or not. If True, subclasses will be passed through. |

`numpy.fmin()`

returns the minimum of `x1`

and `x2`

element-wise. The return type is ndarray or scalar, depending on the input. If both `x1`

and `x2`

are scalars, only then the value returned is scalar.

If one of the elements being compared is

`NaN`

(Not a Number), then thenon-nanelement is returned.

If both elements being compared are

`NaN`

(Not a Number), then`NaN`

is returned.

The examples below show different ways in which `numpy.fmin()`

is used in Python.

The following code example outputs the minimum of two numbers `a`

and `b`

:

import numpy as npa = 10b = 20print(np.fmin(a,b))

The example below outputs the result after comparing the arrays `arr1`

and `arr2`

:

import numpy as nparr1 = np.array([1.5,3.5,4,np.nan])arr2 = np.array([np.nan,6.5,2,np.nan])print(np.fmin(arr1,arr2))

The example below shows the result of comparing the arrays `arr3`

and `arr4`

:

import numpy as nparr3 = np.array([[1,2,3], [4,5,6]])arr4 = np.array([[3,np.nan,1], [6,-5,4]])print(np.fmin(arr3,arr4))

RELATED TAGS

numpy

python

CONTRIBUTOR

Umme Ammara

Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Related Courses