English 中文(简体)
我怎么能解决错误,“在沙里,无属性浮动”。
原标题:How can I solve error "module numpy has no attribute float " in Python?
  • 时间:2022-12-18 20:42:16
  •  标签:
  • python
  • numpy

我正在使用NumPy 1.24.0。

操作这一样本代码线

import numpy as np
num = np.float(3)

我正在发现这一错误:

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 

How can I fix it?

最佳回答

答案已在https://stackoverflow.com/questions/74844262/how-to-solve-error-numpy-has-no-attribute-float-in-python#comment132085333_74844262>@mattdmo

在许多情况下,你可以简单地用等效法的灰色素类取代已折旧的NumPy类,例如,numpy.float 成为“原告”<float

For detailed 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:

......

为绝大多数案件提供明确的指导方针,即使用平原版本的<代码>bool、objectstr(和unicode)的类型是短、清楚的,而且一般来说是好的替代。 float和complex 页: 1 如果你希望更明确地说明准确性。

<代码>np.int, 直接替换为np.int_int>,也很好,不会改变行为,但准确性将继续取决于计算机和操作系统。 如果你想更明确并审查目前的使用情况,你有以下选择:

  • np.int64 or np.int32 to specify the precision exactly. This ensures that results cannot depend on the computer or operating system.
  • np.int_ or int (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.

......

如果你们有使用所解释的类型的依赖,那么快速的工作将是把你的NumPy版本撤回到1.24或更少(如其他一些答复中所建议的那样),同时等待依赖才能赶上。 或者,你可以制造一个包裹,提出拉动要求,或用mon子把依赖性装在你自己的法典中。

问题回答

In the 1.24 version:

The deprecation for the aliases np.object, np.bool, np.float, np.complex, np.str, and np.int is expired (introduces NumPy 1.20). Some of these will now give a FutureWarning in addition to raising an error since they will be mapped to the NumPy scalars in the future.

<代码>pip 安装“numpy<1.24”,以围绕它开展工作。

In [1]: import numpy as np

In [2]: np.__version__
Out[2]:  1.23.5 

In [3]: np.float(3)
<ipython-input-3-8262e04d58e1>:1: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  np.float(3)
Out[3]: 3.0

你们可以使用下列mon子,来管理:

np.float = float    
np.int = int   #module  numpy  has no attribute  int 
np.object = object    #module  numpy  has no attribute  object 
np.bool = bool    #module  numpy  has no attribute  bool 

I solved by updating my "openpyxl" using

{pip install --upgrade openpyxl}

错误在试图读取物时出现。

我删除了numpy.py,然后更新了我的NumPy装置。 它工作了!

注:NumPy版本1.23.3

我在阅读一个xlsx文档时也面临同样的问题。 你们可以把它变为现实,这将解决这个问题。 然而,为了更新 n,你需要获得 n素包的目录:

import numpy
print(numpy.__path__)

更新时,可使用以下代码:

pip install numpy --upgrade

You can also check this page: How can I upgrade NumPy?

在NumPy1.24.0中,float属性从主要NumPy模块中删除。 相反,应当使用<代码>numpy.float64或numpy.float32。 设置浮动点数的班级。

页: 1

import numpy as np
num = np.float64(3)

Pude solucionar ese error instalando esta versión de numpy:
pip install numpy==1.23.3





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签