I am using numpy==1.24.0
.
On running this sample code line:
import numpy as np
num = np.float(3)
I am getting this error:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/ubuntu/.local/lib/python3.8/site-packages/numpy/__init__.py", line 284, in __getattr__
raise AttributeError("module {!r} has no attribute " AttributeError: module 'numpy' has no attribute 'float'
Please help me on this.
CodePudding user response:
I removed numpy.py then updated my numpy and it worked!
Note: numpy version=1.23.3
CodePudding user response:
The answer is already provided in the comments by @mattdmo and @tdelaney:
numpy 1.20 (release notes) deprecated
numpy.float
,numpy.int
, and similar aliases, causing them to issue a deprecation warningnumpy 1.24 (release notes) removed these aliases altogether, causing an error when they are used
For guidelines on how to deal with various deprecated types, have a closer look at the table and guideline in the release notes for 1.20:
...
To give a clear guideline for the vast majority of cases, for the types
bool
,object
,str
(andunicode
) using the plain version is shorter and clear, and generally a good replacement. Forfloat
andcomplex
you can usefloat64
andcomplex128
if you wish to be more explicit about the precision.For
np.int
a direct replacement withnp.int_
orint
is also good and will not change behavior, but the precision will continue to depend on the computer and operating system. If you want to be more explicit and review the current use, you have the following alternatives:
np.int64
ornp.int32
to specify the precision exactly. This ensures that results cannot depend on the computer or operating system.np.int_
orint
(the default), but be aware that it depends on the computer and operating system.- The C types:
np.cint
(int
),np.int_
(long
),np.longlong
.np.intp
which is 32bit on 32bit machines 64bit on 64bit machines. This can be the best type to use for indexing....