Communities for your favorite technologies. Explore all Collectives
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
I don't want any for loop and was wondering if there is a function I can use.
[[1,4,9],[4,9,16]]
If A was the numpy array, I would just type in A*A.
Add a comment
As K. Tom suggested you can do A * A you can also do A ** 2
A * A
A ** 2
import numpy as np array = np.array([1,2,3]) print array * array #[1 4 9] print array ** 2 #[1 4 9]
a = np.array([[100, 200], [50, 150]], dtype=np.uint8); a*a
You could use np.square or np.power:
np.square
np.power
l = [[1,2,3], [2,3,4]] In [5]: np.power(l, 2) Out[5]: array([[ 1, 4, 9], [ 4, 9, 16]], dtype=int32) In [6]: np.square(l) Out[6]: array([[ 1, 4, 9], [ 4, 9, 16]], dtype=int32)
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
[[1,4,9],[4,9,16]]