1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UnicodeWarning: Unicode equal comparison failed ... (numpy.float, Python 2.x)

Last updated at Posted at 2016-04-09

こんにちは。
Python 2.x で、 numpy.float64scipy.sqrt などの返り値も)などの値と unicode literal とを比較すると、 UnicodeWarning となるようです。これに対して math.sqrtの返り値は float なので大丈夫です。

$ python --version
Python 2.7.11
$ python -c "from __future__ import unicode_literals;import math;x=math.sqrt(1);print x.__class__, x=='one'"
<type 'float'> False
$ python -c "from __future__ import unicode_literals;import scipy;x=scipy.sqrt(1);print x.__class__, x=='one'"
-c:1: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
<type 'numpy.float64'> False
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?