Ask Your Question

Revision history [back]

How do I do map/element-wise operations?

I am looking for a way to apply a function to every element of a vector or matrix.

v = vector([2, 0, -3])
print(v)
w = sign(v)
print(w) # I want (1, 0, -1)

m = matrix([[1, 2], [3, 4]])
m = m**2
print(m) # I want [1, 4] [9, 16]

How does this work?