Trusted answers to developer questions

Maria Elijah

The python library `NumPy`

has a method called `multiply()`

which can be used to multiply two input arrays.

`numpy.multiply()`

methodThe ** numpy.multiply() method** returns the product of the two input arrays, element-wise.

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

```
numpy.multiply(arr1, arr2, dtype=None, out=None)
```

: This represents the input data.`arr1`

: This represents the input data.`arr2`

: 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`

The `numpy.prod()`

method returns the product of the `arr1`

and `arr2`

arrays element by element.

Note:If the`out`

parameter is specified, it returns an array reference to`out`

.

The following code shows how to multiply two-dimensional (2D) arrays using the `numpy.multipy()`

method.

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

Implementing the numpy.multiply fucntion

- Line 2: We import the
`numpy`

library. - Lines 4–5: We create two 2D arrays,
`arr1`

and`arr2`

. - Line 9: We use
`np.multiply()`

to multiple the arrays`arr1`

and`arr2`

. - Line 11: We display the result.

RELATED TAGS

numpy

python3

CONTRIBUTOR

Maria Elijah

RELATED COURSES

View all Courses

Keep Exploring

Related Courses