Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have two array a and b such that b's shape is a row of a. I want to multiply b to each row of a so for example,
a
b
#a [[1,2,3] [4,5,6] [7,8,9]] #b [1,3,2] # a times b [[1,6,6] [4,15,12] [7,24,18]]
Is there any way to perform it?
a * b
This is actually the expected output when using numpy. So in your case:
import numpy as np a = np.array([[1,2,3], [4,5,6], [7,8,9]]) b = np.array([1,3,2]) c = a*b
c will be:
array([[ 1, 6, 6], [ 4, 15, 12], [ 7, 24, 18]])
Add a comment
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
a * b