Giovanni, try this instead: sage: numpy.random.multinomial(10, [.5,.5], size=20r)
The only difference is the "r" suffix to the size argument. When you type in numbers into sage, the pre-processor converts them to a base ring, which you can see by doing: sage: preparse('numpy.random.multinomial(10, [.5,.5], size=20)') "numpy.random.multinomial(Integer(10), [RealNumber('.5'),RealNumber('. 5')], size=Integer(20))" Numpy support of these advanced sage types like Integer or RealNumber is spotty, so appending the "r" suffix (r for raw) to numbers prevents them from being preparsed. This is a sage thing, doesn't mean anything in regular python. Another way to accomplish this is to pass in "size=int(20)". Sometimes it's a matter of guessing which number isn't playing nice. There are a couple of things you can try: 1) If you are doing only Numpy stuff and don't need any sage-specific tools, you can use ipython without sage: "sage -ipython", or in the notebook, by either choosing "python" in the syntax drop-down menu instead of "sage", or by putting "%python" as the first line of cells. 2) Turn off the preprocessor before chunks of Numpy code: "preparse (False)". 3) Find out where in the numpy or sage code this error is happening and fix it. See Martin Albrecht's talk, '''How to get started developing Sage" at http://wiki.sagemath.org/days16 Best, Ahmed On Jun 26, 10:25 am, "giovanni.marche...@ds.unifi.it" <giovanni.m.marche...@gmail.com> wrote: > I would like to sample from a multinomial distribution. > > What's wrong in the following statements in sage 4.0.1? > > >>> import numpy.random > >>> numpy.random.multinomial(10, [.5,.5], size=20) > > Thank you > > -- Giovanni > > Traceback (click to the left for traceback) > ... > TypeError: unsupported operand parent(s) for '+': 'Integer Ring' and > '<type 'tuple'>' > > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "/home/gmm/.sage/sage_notebook/worksheets/admin/41/code/ > 265.py", line 7, in <module> > numpy.random.multinomial(_sage_const_10 , > [_sage_const_p5 ,_sage_const_p5 ], size=_sage_const_20 ) > File "/home/gmm/sage-4.0.1/local/lib/python2.5/site-packages/ > Jinja-1.2-py2.5-linux-x86_64.egg/", line 1, in <module> > > File "mtrand.pyx", line 2655, in mtrand.RandomState.multinomial > File "element.pyx", line 729, in > sage.structure.element.ModuleElement.__add__ (sage/structure/element.c: > 6528) > File "coerce.pyx", line 740, in > sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure/ > coerce.c:6584) > TypeError: unsupported operand parent(s) for '+': 'Integer Ring' and > '<type 'tuple'>' --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---