Trusted answers to developer questions

Maria Elijah

The python library NumPy has a method called `floor_divide()`

which can be used to divide two input arrays.

`numpy.floor_divide()`

methodThe ** numpy.floor_divide() method** divides the first array’s elements by the elements of the second array. This is done element-wise (element by element).

Note:A two-dimensional (2D) array can be created using a list of lists in Python.

```
numpy.floor_divide(x1, x2, dtype=None, out=None)
```

: This represents the input data.`x1`

: This represents the input data.`x2`

: This is an optional parameter. It represents the return type of the array.`dtype`

: This is an optional parameter. It represents the alternative output array in which the result is to be placed.`out`

Note:If`x1`

and`x2`

have distinct shapes, they must be able to be broadcasted to a common shape for output representation.

The `numpy.floor_divide()`

method returns a floor array of `(x1/x2)`

.

Note:In Python, the operator`//`

is equivalent to the function`floor_divide()`

.

The following code shows how to use the `numpy.floor_divide()`

method for two-dimensional(2D) arrays.

# import numpy import numpy as np # create a two 2D arrays x1 = np.array([[2,6,5],[3,4,8]]) x2 = np.array([[1,7,2],[10,9,4]]) # divide the 2D arrays # and store the result in result result = np.floor_divide(x1, x2) print(result)

Using the np.floor_divide() function

- Line 2: We import the
`numpy`

library. - Lines 4–5: We create two 2D arrays called
`x1`

and`x2`

. - Line 9: We use the
`np.floor_divider()`

which divides the array`x1`

by`x2`

. The result is stored in a new variable called`result`

. - Line 11: We display the result.

RELATED TAGS

python

python3

numpy

CONTRIBUTOR

Maria Elijah

RELATED COURSES

View all Courses

Keep Exploring

Related Courses