当前位置:   article > 正文

NumPy的数组_raise attributeerror("module {!r} has no attribute

raise attributeerror("module {!r} has no attribute " attributeerror: module

  1. Windows PowerShell
  2. Copyright (C) Microsoft Corporation. All rights reserved.
  3. Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
  4. PS C:\Users\a-xiaobodou> python -m pip install --upgrade pip
  5. C:\msys64\mingw64\bin\python.exe: No module named pip
  6. PS C:\Users\a-xiaobodou> python -m pip install numpy
  7. C:\msys64\mingw64\bin\python.exe: No module named pip
  8. PS C:\Users\a-xiaobodou> python3 -m pip install numpy
  9. C:\msys64\mingw64\bin\python3.exe: No module named pip
  10. PS C:\Users\a-xiaobodou> pip install numpy
  11. Requirement already satisfied: numpy in c:\users\a-xiaobodou\appdata\local\programs\python\python310\lib\site-packages (1.22.3)
  12. PS C:\Users\a-xiaobodou> python -i
  13. Python 3.9.11 (main, Mar 18 2022, 16:54:01) [GCC 11.2.0 64 bit (AMD64)] on win32
  14. Type "help", "copyright", "credits" or "license" for more information.
  15. >>> from numpy import *
  16. Traceback (most recent call last):
  17. File "<stdin>", line 1, in <module>
  18. ModuleNotFoundError: No module named 'numpy'
  19. >>> eye(4)
  20. Traceback (most recent call last):
  21. File "<stdin>", line 1, in <module>
  22. NameError: name 'eye' is not defined
  23. >>>

不明白,为什么在命令提示符出现ModuleNotFoundError:No mudule namy 'numpy'

  1. Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32
  2. Type "help", "copyright", "credits" or "license" for more information.
  3. >>> from numpy import *
  4. >>> eye(4)
  5. array([[1., 0., 0., 0.],
  6. [0., 1., 0., 0.],
  7. [0., 0., 1., 0.],
  8. [0., 0., 0., 1.]])
  9. >>>

  1. Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32
  2. Type "help", "copyright", "credits" or "license" for more information.
  3. >>> import numpy as np
  4. >>> my_array=np.array([1,2,3,4,5])
  5. >>> print my_array
  6. File "<stdin>", line 1
  7. print my_array
  8. ^^^^^^^^^^^^^^
  9. SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
  10. >>> print my_array
  11. File "<stdin>", line 1
  12. print my_array
  13. ^^^^^^^^^^^^^^
  14. SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
  15. >>> print(my_array)
  16. [1 2 3 4 5]
  17. >>> print(my_array.shape)
  18. (5,)
  19. >>> print(my_array[0])
  20. 1
  21. >>> my_array[0]=-1
  22. >>> print(my_array[0])
  23. -1
  24. >>> print(my_array)
  25. [-1 2 3 4 5]
  26. >>> my_new_array=np.zeros((5))
  27. >>> print(my_random_array)
  28. Traceback (most recent call last):
  29. File "<stdin>", line 1, in <module>
  30. NameError: name 'my_random_array' is not defined. Did you mean: 'my_new_array'?
  31. >>> print(my_new_array)
  32. [0. 0. 0. 0. 0.]
  33. >>> my_random_array=np.radom.radom((5))
  34. Traceback (most recent call last):
  35. File "<stdin>", line 1, in <module>
  36. File "C:\Users\a-xiaobodou\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\__init__.py", line 315, in __getattr__
  37. raise AttributeError("module {!r} has no attribute "
  38. AttributeError: module 'numpy' has no attribute 'radom'. Did you mean: 'random'?
  39. >>> my_random_array=np.random.radom((5))
  40. Traceback (most recent call last):
  41. File "<stdin>", line 1, in <module>
  42. AttributeError: module 'numpy.random' has no attribute 'radom'. Did you mean: 'random'?
  43. >>> my_random_array=np.random.random((5))
  44. >>> print(my_random_array)
  45. [0.25351566 0.7168677 0.13383434 0.56201388 0.80009886]
  46. >>> my_2d_array=np.zeros((2,3)) print(my_2d_array)
  47. File "<stdin>", line 1
  48. my_2d_array=np.zeros((2,3)) print(my_2d_array)
  49. ^^^^^
  50. SyntaxError: invalid syntax
  51. >>> my_2d_array=np.zeros((2,3))
  52. >>> print(my_ad_array)
  53. Traceback (most recent call last):
  54. File "<stdin>", line 1, in <module>
  55. NameError: name 'my_ad_array' is not defined. Did you mean: 'my_2d_array'?
  56. >>> print(my_2d_array)
  57. [[0. 0. 0.]
  58. [0. 0. 0.]]
  59. >>> my_ad_array_new=np.ones((2,4))
  60. >>> print(my_2d_array_new)
  61. Traceback (most recent call last):
  62. File "<stdin>", line 1, in <module>
  63. NameError: name 'my_2d_array_new' is not defined. Did you mean: 'my_ad_array_new'?
  64. >>> print(my_ad_array_new)
  65. [[1. 1. 1. 1.]
  66. [1. 1. 1. 1.]]
  67. >>> my_array=np.array([4,5],[6,1])
  68. Traceback (most recent call last):
  69. File "<stdin>", line 1, in <module>
  70. TypeError: Field elements must be 2- or 3-tuples, got '6'
  71. >>> my_array=np.array([[4,5],[6,1]])
  72. >>> print(my_array[0][1])
  73. 5
  74. >>> print(my_array)
  75. [[4 5]
  76. [6 1]]
  77. >>> print(my_array.shape)
  78. (2, 2)
  79. >>> my_array_column_2=my_array[:,1]
  80. >>> print(my_array_colum_2)
  81. Traceback (most recent call last):
  82. File "<stdin>", line 1, in <module>
  83. NameError: name 'my_array_colum_2' is not defined. Did you mean: 'my_array_column_2'?
  84. >>> print(my_array_column_2)
  85. [5 1]
  86. >>>

  1. Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32
  2. Type "help", "copyright", "credits" or "license" for more information.
  3. >>> import numpy as np
  4. >>> a=np.array([[1.0,2.0],[3.0,4.0]])
  5. >>> b=np.array([[5.0,6.0],[7.0,8.0]])
  6. >>> sum=a+b
  7. >>> difference=a-b
  8. >>> product=a*b
  9. >>> quotient=a/b
  10. >>> print('Sum=\n',sum)
  11. Sum=
  12. [[ 6. 8.]
  13. [10. 12.]]
  14. >>> print('Difference =\n',difference)
  15. Difference =
  16. [[-4. -4.]
  17. [-4. -4.]]
  18. >>> print('Product =\n',product)
  19. Product =
  20. [[ 5. 12.]
  21. [21. 32.]]
  22. >>> print('Quotient =\n', quotient)
  23. Quotient =
  24. [[0.2 0.33333333]
  25. [0.42857143 0.5 ]]
  26. >>>
  27. >>> print(a)
  28. [[1. 2.]
  29. [3. 4.]]
  30. >>> print(b)
  31. [[5. 6.]
  32. [7. 8.]]
  33. >>>
  34. >>> matrix_product=a.dot(b)
  35. >>> print("Matrix Product = ",matrix_product)
  36. Matrix Product = [[19. 22.]
  37. [43. 50.]]
  38. >>>

ndarray对象属性
属性说明
ndarray.ndim秩,即轴的数量 或维度的数量
ndarray.shape数组的维度,对于矩阵,为n行m列
ndarray.size数组元素的总个数,相当于.shape中n×m的值
ndarray.dtypendarray对象的元素类型
ndarray.itemsizendarray对象中每个元素的大小,以字节为单位
ndarray.flagsndarray对象的内存信息
ndarray.realndarray元素的实部
ndarray.imagndarray元素的虚部
ndarray.data包含实际数组元素的缓冲区,由于一般通过数组的索引获取元素,所以通常不需要使用这个属性

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/225005
推荐阅读
相关标签
  

闽ICP备14008679号