Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows PS C:Usersa-xiaobodou> python -m pip install --upgrade pip C:msys64mingw64binpython.exe: No module named pip PS C:Usersa-xiaobodou> python -m pip install numpy C:msys64mingw64binpython.exe: No module named pip PS C:Usersa-xiaobodou> python3 -m pip install numpy C:msys64mingw64binpython3.exe: No module named pip PS C:Usersa-xiaobodou> pip install numpy Requirement already satisfied: numpy in c:usersa-xiaobodouappdatalocalprogramspythonpython310libsite-packages (1.22.3) PS C:Usersa-xiaobodou> python -i Python 3.9.11 (main, Mar 18 2022, 16:54:01) [GCC 11.2.0 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from numpy import * Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'numpy' >>> eye(4) Traceback (most recent call last): File " ", line 1, in NameError: name 'eye' is not defined >>>
不明白,为什么在命令提示符出现ModuleNotFoundError:No mudule namy 'numpy'
Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from numpy import *
>>> eye(4)
array([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]])
>>>
Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy as np >>> my_array=np.array([1,2,3,4,5]) >>> print my_array File "", line 1 print my_array ^^^^^^^^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)? >>> print my_array File " ", line 1 print my_array ^^^^^^^^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)? >>> print(my_array) [1 2 3 4 5] >>> print(my_array.shape) (5,) >>> print(my_array[0]) 1 >>> my_array[0]=-1 >>> print(my_array[0]) -1 >>> print(my_array) [-1 2 3 4 5] >>> my_new_array=np.zeros((5)) >>> print(my_random_array) Traceback (most recent call last): File " ", line 1, in NameError: name 'my_random_array' is not defined. Did you mean: 'my_new_array'? >>> print(my_new_array) [0. 0. 0. 0. 0.] >>> my_random_array=np.radom.radom((5)) Traceback (most recent call last): File " ", line 1, in File "C:Usersa-xiaobodouAppDataLocalProgramsPythonPython310libsite-packagesnumpy__init__.py", line 315, in __getattr__ raise AttributeError("module {!r} has no attribute " AttributeError: module 'numpy' has no attribute 'radom'. Did you mean: 'random'? >>> my_random_array=np.random.radom((5)) Traceback (most recent call last): File " ", line 1, in AttributeError: module 'numpy.random' has no attribute 'radom'. Did you mean: 'random'? >>> my_random_array=np.random.random((5)) >>> print(my_random_array) [0.25351566 0.7168677 0.13383434 0.56201388 0.80009886] >>> my_2d_array=np.zeros((2,3)) print(my_2d_array) File " ", line 1 my_2d_array=np.zeros((2,3)) print(my_2d_array) ^^^^^ SyntaxError: invalid syntax >>> my_2d_array=np.zeros((2,3)) >>> print(my_ad_array) Traceback (most recent call last): File " ", line 1, in NameError: name 'my_ad_array' is not defined. Did you mean: 'my_2d_array'? >>> print(my_2d_array) [[0. 0. 0.] [0. 0. 0.]] >>> my_ad_array_new=np.ones((2,4)) >>> print(my_2d_array_new) Traceback (most recent call last): File " ", line 1, in NameError: name 'my_2d_array_new' is not defined. Did you mean: 'my_ad_array_new'? >>> print(my_ad_array_new) [[1. 1. 1. 1.] [1. 1. 1. 1.]] >>> my_array=np.array([4,5],[6,1]) Traceback (most recent call last): File " ", line 1, in TypeError: Field elements must be 2- or 3-tuples, got '6' >>> my_array=np.array([[4,5],[6,1]]) >>> print(my_array[0][1]) 5 >>> print(my_array) [[4 5] [6 1]] >>> print(my_array.shape) (2, 2) >>> my_array_column_2=my_array[:,1] >>> print(my_array_colum_2) Traceback (most recent call last): File " ", line 1, in NameError: name 'my_array_colum_2' is not defined. Did you mean: 'my_array_column_2'? >>> print(my_array_column_2) [5 1] >>>
Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> a=np.array([[1.0,2.0],[3.0,4.0]])
>>> b=np.array([[5.0,6.0],[7.0,8.0]])
>>> sum=a+b
>>> difference=a-b
>>> product=a*b
>>> quotient=a/b
>>> print('Sum=n',sum)
Sum=
[[ 6. 8.]
[10. 12.]]
>>> print('Difference =n',difference)
Difference =
[[-4. -4.]
[-4. -4.]]
>>> print('Product =n',product)
Product =
[[ 5. 12.]
[21. 32.]]
>>> print('Quotient =n', quotient)
Quotient =
[[0.2 0.33333333]
[0.42857143 0.5 ]]
>>>
>>> print(a)
[[1. 2.]
[3. 4.]]
>>> print(b)
[[5. 6.]
[7. 8.]]
>>>
>>> matrix_product=a.dot(b)
>>> print("Matrix Product = ",matrix_product)
Matrix Product = [[19. 22.]
[43. 50.]]
>>>



