Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
sage: A = vector([1,2,3])
(1, 8, 27)
sage: A.apply_map(2*x^3)
(2, 16, 54)
sage: A.apply_map(sin(x))
(sin(1), sin(2), sin(3))

Note that the first time you do this you might get a warning.

sage: A.apply_map(x^3)
/Users/.../sage-5.8.beta3/local/lib/python2.7/site-packages/IPython/core/ DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
See for details.
  exec code_obj in self.user_global_ns, self.user_ns

So you wouldn't want to rely on that syntax long-term. There are several ways around this; here's one.

sage: A = vector([1,2,3])
sage: A.apply_map(lambda x: sin(x))
(sin(1), sin(2), sin(3))