sage: import pylab as p sage: x = p.arange(-100, 300, 10) sage: type(x) <type 'numpy.ndarray'>
as you can see x is an object of type 'numpy.ndarray', abs is a Python built-in method, which means that you can apply abs(x) to each object x for which a __abs__ method is defined, and so is obviously for type 'numpy.ndarray'. cos() is a sage function, it cannot be applied to objects of type 'numpy.array', it also cannot be applied to Python objects of type 'list', you have to write: sage: y = [cos(a) for a in x] to obtain the desired result, namely a list which fits to x, this is very easy and inconsiderably more effort than writing 'y = cos(x)' which may be the reason why cos() is not implemented for list objects, it's just not necessary, but actually I have to confess, I don't know... if you want to run this example on a Python Shell you can also write: >>>y = p.cos(x) instead, i.e using the pylab.cos function which can be applied to objects of type 'numpy.ndarray' in a pointwise manner, but if you run this on the sage command line you have the problem that p.arange() outputs a 'numpy.ndarray' which elements are of type 'Integer' (a sage type, this is because the line 'x = p.arange(5)' is parsed to 'x = p.arange(Integer(5))' and then passed to the Python Shell) and p.cos() cannot be applied to objects of type 'Integer', so don't write sage: y = p.cos(x) this object type mess imho is a drawback of the approach to use Python as an interpreter, it's confusing for beginners, but on the other side an amazingly powerful tool if you once got it and definitely it's worth the effort to learn Python.... on the sage prompt i would use the srange function, (if guess srange stands for sage range), it returns objects of the same type as the input, i.e. srange(5) applied on the sage prompt returns a list with members of type 'Integer'), sage: x = srange(-100, 300, 10) the whole example then is like: sage: import pylab as p sage: x = srange(-100, 300, 10) sage: y = [cos(a) for a in x] sage: p.plot(x, y, 'go') sage: p.savefig('plot.png') instead of the last two lines you can also use sage's plotting functions and objects, Georg --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---