ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 14 Oct 2017 06:33:00 -0500x=var('x') - getting TypeError: cannot perform reduce with flexible typehttp://ask.sagemath.org/question/10805/xvarx-getting-typeerror-cannot-perform-reduce-with-flexible-type/I just installed Sage 5.12 under Mac OSX 10.9 (Mavericks). I started the notebook and then proceeded to work through the "Getting started" document. In Chapter One, the first page there is an example of Symbolic programming. It starts with:
x=var('x')
When I evaluate this I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_16.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("eD12YXIoJ3gnKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/private/var/folders/k_/vvbn4jxs6jx2z21s7xdj088c0000gq/T/tmpZ3Z0gy/___code___.py", line 2, in <module>
exec compile(u"x=var('x')" + '\n', '', 'single')
File "", line 1, in <module>
File "/Applications/Sage-5.12-OSX-64bit-10.8.app/Contents/Resources/sage/local/lib/python2.7/site-packages/numpy/core/fromnumeric.py", line 2693, in var
keepdims=keepdims)
File "/Applications/Sage-5.12-OSX-64bit-10.8.app/Contents/Resources/sage/local/lib/python2.7/site-packages/numpy/core/_methods.py", line 68, in _var
arrmean = um.add.reduce(arr, axis=axis, dtype=dtype, keepdims=True)
TypeError: cannot perform reduce with flexible type
DOES ANYONE KNOW WHAT IS WRONG WITH THIS?
If I try this from the SAGE command line (as opposed to the notebook) it appears to work. Am I doing something fundamentally wrong by using the notebook for this?
It is Sage's own introductory example, and it is not working! It is the first thing I tried, so it does not give one confidence with the system.
The error appears to be emanating from it's own internal version of Python.
Thanks in advance for any help.
Regards.
Bob
Wed, 04 Dec 2013 17:44:48 -0600http://ask.sagemath.org/question/10805/xvarx-getting-typeerror-cannot-perform-reduce-with-flexible-type/Answer by AstroFloyd for <p>I just installed Sage 5.12 under Mac OSX 10.9 (Mavericks). I started the notebook and then proceeded to work through the "Getting started" document. In Chapter One, the first page there is an example of Symbolic programming. It starts with:</p>
<pre><code>x=var('x')
</code></pre>
<p>When I evaluate this I get the following error:</p>
<pre><code>Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_16.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("eD12YXIoJ3gnKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/private/var/folders/k_/vvbn4jxs6jx2z21s7xdj088c0000gq/T/tmpZ3Z0gy/___code___.py", line 2, in <module>
exec compile(u"x=var('x')" + '\n', '', 'single')
File "", line 1, in <module>
File "/Applications/Sage-5.12-OSX-64bit-10.8.app/Contents/Resources/sage/local/lib/python2.7/site-packages/numpy/core/fromnumeric.py", line 2693, in var
keepdims=keepdims)
File "/Applications/Sage-5.12-OSX-64bit-10.8.app/Contents/Resources/sage/local/lib/python2.7/site-packages/numpy/core/_methods.py", line 68, in _var
arrmean = um.add.reduce(arr, axis=axis, dtype=dtype, keepdims=True)
TypeError: cannot perform reduce with flexible type
</code></pre>
<p>DOES ANYONE KNOW WHAT IS WRONG WITH THIS?</p>
<p>If I try this from the SAGE command line (as opposed to the notebook) it appears to work. Am I doing something fundamentally wrong by using the notebook for this?</p>
<p>It is Sage's own introductory example, and it is not working! It is the first thing I tried, so it does not give one confidence with the system.</p>
<p>The error appears to be emanating from it's own internal version of Python.</p>
<p>Thanks in advance for any help.</p>
<p>Regards.</p>
<p>Bob </p>
http://ask.sagemath.org/question/10805/xvarx-getting-typeerror-cannot-perform-reduce-with-flexible-type/?answer=39158#post-id-39158Thank you - I had a similar issue with the f(x) = cos(x) example. In my case, I found the solution in ~/.ipython/profile_default/ipython_config.py, by commenting out the line c.InteractiveShellApp.pylab = 'auto', which also seems to import numpy.Sat, 14 Oct 2017 06:33:00 -0500http://ask.sagemath.org/question/10805/xvarx-getting-typeerror-cannot-perform-reduce-with-flexible-type/?answer=39158#post-id-39158Answer by bigduke for <p>I just installed Sage 5.12 under Mac OSX 10.9 (Mavericks). I started the notebook and then proceeded to work through the "Getting started" document. In Chapter One, the first page there is an example of Symbolic programming. It starts with:</p>
<pre><code>x=var('x')
</code></pre>
<p>When I evaluate this I get the following error:</p>
<pre><code>Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_16.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("eD12YXIoJ3gnKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/private/var/folders/k_/vvbn4jxs6jx2z21s7xdj088c0000gq/T/tmpZ3Z0gy/___code___.py", line 2, in <module>
exec compile(u"x=var('x')" + '\n', '', 'single')
File "", line 1, in <module>
File "/Applications/Sage-5.12-OSX-64bit-10.8.app/Contents/Resources/sage/local/lib/python2.7/site-packages/numpy/core/fromnumeric.py", line 2693, in var
keepdims=keepdims)
File "/Applications/Sage-5.12-OSX-64bit-10.8.app/Contents/Resources/sage/local/lib/python2.7/site-packages/numpy/core/_methods.py", line 68, in _var
arrmean = um.add.reduce(arr, axis=axis, dtype=dtype, keepdims=True)
TypeError: cannot perform reduce with flexible type
</code></pre>
<p>DOES ANYONE KNOW WHAT IS WRONG WITH THIS?</p>
<p>If I try this from the SAGE command line (as opposed to the notebook) it appears to work. Am I doing something fundamentally wrong by using the notebook for this?</p>
<p>It is Sage's own introductory example, and it is not working! It is the first thing I tried, so it does not give one confidence with the system.</p>
<p>The error appears to be emanating from it's own internal version of Python.</p>
<p>Thanks in advance for any help.</p>
<p>Regards.</p>
<p>Bob </p>
http://ask.sagemath.org/question/10805/xvarx-getting-typeerror-cannot-perform-reduce-with-flexible-type/?answer=23642#post-id-23642Hi,
Sage is based on Python. This error comes from numpy.var function (variance calculation on numeric array) like numpy.var([1,2,3]) = 0.6666666666663. I had the same problem because I use a pythonrc.py file which import all from numpy (from numpy import *) each time I start a python console. Commenting this import will solve the problem and Sage will recognize the var function (which comes from sympy.var, var as variable not variance).
So in Sage : x=var('x') won't produce any error and it works fine.
Another solution is to "import numpy as np" or simply "import numpy" to make sure we don't overwrite "variable" with "variance".
;)
bigdukeWed, 30 Jul 2014 17:05:42 -0500http://ask.sagemath.org/question/10805/xvarx-getting-typeerror-cannot-perform-reduce-with-flexible-type/?answer=23642#post-id-23642