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 an array:
one = np.array([[1], [0]])
How arr can be created such that, every element of arr would be equal to one?
arr
one
If I do:
arr = one * 4
Due to broadcasting above statement doesn't give the desired behavior.
* 4
Use repeat:
repeat
np.repeat(one[np.newaxis, ...], 4, axis=0)
Alternatively, you can try broadcast_to. This will be faster but read-only:
broadcast_to
np.broadcast_to(one, (4, *one.shape))
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.
arrsupposed to be? With lists* 4is a replication, but with arrays it is plain numeric multiplication.