AttributeError: module 'numpy' has no attribute 'int'
Asked Answered
N

3

21

I tried to run my code in another computer, while it successfully compiled in the original environment, this error can outta nowhere:

File "c:\vision_hw\hw_3\cv2IP.py", line 91, in SECOND_ORDER_LOG
    original = np.zeros((5,5),dtype=np.int)
File "C:\Users\brian2lee\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\numpy\__init__.py", line 284, in __getattr__
    raise AttributeError("module {!r} has no attribute " AttributeError: module 'numpy' has no attribute 'int'

I have tried reinstallin numpy but it did not work. Down below is my code:

def SECOND_ORDER_LOG (self,img):
    original = np.zeros((5,5),dtype=np.int)
    original[2,2] = 1
    kernel = np.array([[ 0,  0, -1,  0,  0],
    [ 0, -1, -2, -1,  0],
    [-1, -2, 16, -2, -1],
    [ 0, -1, -2, -1,  0],
    [ 0,  0, -1,  0,  0]])
    result = original + 1 * kernel
    sharpened = cv2.filter2D(img, -1, result)
    return sharpened
Necrolatry answered 29/12, 2022 at 3:1 Comment(0)
G
28

numpy.int was deprecated in NumPy 1.20 and was removed in NumPy 1.24. You can change it to numpy.int_, or just int.

Several other aliases for standard types were also removed from NumPy's namespace on the same schedule:

Deprecated name Identical to NumPy scalar type names
numpy.bool bool numpy.bool_
numpy.int int numpy.int_ (default), numpy.int64, or numpy.int32
numpy.float float numpy.float64, numpy.float_, numpy.double (equivalent)
numpy.complex complex numpy.complex128, numpy.complex_, numpy.cdouble (equivalent)
numpy.object object numpy.object_
numpy.str str numpy.str_
numpy.long int numpy.int_ (C long), numpy.longlong (largest integer type)
numpy.unicode str numpy.unicode_

There are similar AttributeError messages for these removals (listing them helps people find this Q&A in the search results):

  • AttributeError: module 'numpy' has no attribute 'bool'.
  • AttributeError: module 'numpy' has no attribute 'int'.
  • AttributeError: module 'numpy' has no attribute 'float'.
  • AttributeError: module 'numpy' has no attribute 'complex'.
  • AttributeError: module 'numpy' has no attribute 'object'.
  • AttributeError: module 'numpy' has no attribute 'str'.
  • AttributeError: module 'numpy' has no attribute 'long'.
  • AttributeError: module 'numpy' has no attribute 'unicode'.
Greenshank answered 29/12, 2022 at 3:15 Comment(0)
P
6
np.int = np.int32
np.float = np.float64
np.bool = np.bool_

boruta = BorutaPy(estimator=rf)
boruta.fit(x, y)

from here

Patrickpatrilateral answered 16/2 at 6:48 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Kirakiran
A
0

The error you're seeing (AttributeError: module 'numpy' has no attribute 'int') suggests that you're trying to use numpy.int, which isn't an attribute in numpy. However, there's numpy.int_, which is the exact equivalent of Python's built-in int but it's available for array operations inside numpy.

If you're not working within the numpy framework for the task causing this error, it's recommended to simply use Python's built-in int.

numpy.int (along with other similar types) was deprecated in NumPy 1.20 and subsequently removed in NumPy 1.24. Therefore, using numpy.int in versions after 1.24 will raise an error. Since numpy.int is now removed, using native Python's int type is the easiest replacement when numpy's specific capabilities aren't needed.

Amplify answered 12/8, 2023 at 11:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.