开发者

Help with this typerror in a dictionary

 benfordd = dict()
 for attr in attrs:
      benfordd.setdefault(attr, []).ex开发者_C百科tend([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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜