You can find the answer here (look for fromfunction): http://dsnra.jpl.nasa.gov/software/Python/numpydoc/numpy-6.html
On Nov 26, 9:45 pm, William Stein <[email protected]> wrote: > On Wed, Nov 25, 2009 at 10:07 PM, shaunc <[email protected]> wrote: > > Hello! > > > I am new to sage -- but an experienced python user. > > I have successfully installed sage (except for plotting on mac 10.6 -- > > but I understand that's being worked on). > > > I wanted to build a vector of random numbers, and did the following: > > > sage: import random > > sage: import numpy as N > > sage: u = random.uniform > > sage: N.fromfunction( lambda i: u( 0., 1. ), ( 3, ) ) > > 0.513723977031280 > > > !! why not an array? > > > However, the following works slightly differently.... > > > sage: N.fromfunction( lambda i: u( 0.*i, 1. ), ( 3, ) ) > > array([ 0.65361094, 0.65361094, 0.65361094]) > > > It would seem that sage is trying to optimize the expression... (but > > not very systematically, as the difference of the answers shows). > > > Even stranger: > > sage: N.fromfunction( ( lambda i: u( 0, 1.*i ) ), ( 3, ) ) > > array([ 0. , 0.92293102, 1.84586204]) > > > Here it seems to have called u once and then scaled the result??? > > > Can I turn this off -- it seems likely to cause bugs?! And in any > > case, why doesn't it give me an array of 3 constants in the first > > case? > > These seem to all be NumPy questions. You might also want to post > to the NumPy mailing list: > > http://www.scipy.org/Mailing_Lists > > William -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
