Ask Your Question
4

How can one perform multiplication on a one-dimensional array in Python?

asked 2021-12-09 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-10-01 10:00:00 +0000

djk gravatar image

You can perform multiplication on a one-dimensional array in Python using the numpy library. Here's an example:

import numpy as np

arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])

# Multiply two arrays element-wise
result = arr1 * arr2

print(result) # Output: [ 4 10 18 ]

In the above example, we first import the numpy library and create two one-dimensional arrays arr1 and arr2. To perform multiplication on these arrays, we simply use the * operator, which multiplies the corresponding elements in each array. The resulting array is stored in the variable result and printed to the console.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-12-09 11:00:00 +0000

Seen: 1 times

Last updated: Oct 01 '22