user365930
user365930

Reputation: 77

Help with this typerror in a dictionary

 benfordd = dict()
 for attr in attrs:
      benfordd.setdefault(attr, []).extend([val*1e6 for val in x if not np.isnan(val)])

the above is just parts of my code, why is it that when I run this in ipython, I get this:

TypeError: function not supported for these types, and can't coerce safely to supported types.

does anyone know what values are needed for this? attr are strings.

p.s., what does "val" stand for?

Upvotes: 1

Views: 160

Answers (1)

Katriel
Katriel

Reputation: 123762

I believe this error can occur when using Sage with numpy. The reason is that Sage preparses your input, so that e.g. 0.6**2 is translated to RealNumber('0.6') ** Integer(2). This allows it to handle real numbers with arbitrary precision. Unfortunately, numpy can't handle these, because it doesn't know what a RealNumber is.

If you define RealNumber = float, the code should work; see the docs.

Upvotes: 1

Related Questions