Ask Your Question

x=var('x') - getting TypeError: cannot perform reduce with flexible type

asked 2013-12-04 17:44:48 -0500

BobBetz gravatar image

updated 2013-12-05 15:08:08 -0500

ppurka gravatar image

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:


When I evaluate this I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "", line 10, in <module>
    exec compile(u'open("","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("eD12YXIoJ3gnKQ=="),globals())+"\\n"); execfile(os.path.abspath(""))
  File "", line 1, in <module>

  File "/private/var/folders/k_/vvbn4jxs6jx2z21s7xdj088c0000gq/T/tmpZ3Z0gy/", line 2, in <module>
    exec compile(u"x=var('x')" + '\n', '', 'single')
  File "", line 1, in <module>

  File "/Applications/", line 2693, in var
  File "/Applications/", line 68, in _var
    arrmean = um.add.reduce(arr, axis=axis, dtype=dtype, keepdims=True)
TypeError: cannot perform reduce with flexible type


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.



edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-07-30 17:05:42 -0500

bigduke gravatar image

updated 2014-07-31 06:32:16 -0500


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 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".



edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2013-12-04 17:44:48 -0500

Seen: 907 times

Last updated: Jul 31 '14