Hi Sage-Devel,
I just spent the week teaching numpy and matplotlib in the context of
Sage. Walking around and watching why/how students got frustrated on
certain homework problems revealed one way we could improve Sage,
which would make Sage much more useful and natural overall. It
seems to me that this shouldn't be impossibly hard.
Consider:
sag: import numpy as np
sage: t = np.arange(5); t
array([0, 1, 2, 3, 4])
sage: t^2 + sin(2*t)
array([ 0. , 1.90929743, 3.2431975 , 8.7205845 , 16.98935825])
So far this is great -- it's awesome that basic sage symbolic
functions like sin, cos, exp, etc., can take numpy arrays as input.
Much better than the situation with python:
sage: math.sin(t) # BOOM
However, we have the following, which frustrated my students a lot:
sage: f(x) = x^2 + sin(2*x)
sage: f(t)
BOOM ...
NotImplementedError: Numpy arrays are not supported as arguments for
symbolic expressions
Yep, it's not implemented. I think it would be great if this were
implemented. The semantics are pretty clear -- apply component-wise
and get a numpy array. Under the hood this should use fast_callable.
Anyway, just a wishlist thing, but it would be nice to make Sage a bit
more usable in a way that doesn't raise any subtle design questions...
-- William
https://cloud.sagemath.com/projects/4a5f0542-5873-4eed-a85c-a18c706e8bcd/files/support/2016-05-20-142756-numpy-ufunc.sagews
--
William (
http://wstein.org)