Skip to content Skip to sidebar Skip to footer

Length-1 Arrays Can Be Converted To Python Scalars Error? Python

from numpy import * from pylab import * from math import * def LogisticMap(a,x): return 4.*a*x*(1.-x) def CosineMap(a,x): return a*cos(x/(2.*pi)) def TentMap(a,x): i

Solution 1:

You first import numpy.cos, and then import math.cos. The latter shadows the former, and doesn't know how to handle NumPy arrays. Hence the error.

To fix, try:

import numpy

defCosineMap(a,x):
    return a*numpy.cos(x/(2.*pi))

Problems of this sort are a good reason to avoid from X import *-style imports.

As to TentMap, here is one way to vectorize it correctly:

defTentMap(a,x):
    return2.*a*numpy.minimum(x, 1.-x)

Post a Comment for "Length-1 Arrays Can Be Converted To Python Scalars Error? Python"