numpy function guide: an overview of commonly used functions and their functions in the numpy library, specific code examples are required
Introduction:
NumPy is a Python library for science The core library of computing provides a large number of efficient array operation functions and tools. It has been widely used in fields such as data processing, numerical computing and machine learning. This article will introduce some commonly used NumPy functions, as well as their specific functions and usage, and provide corresponding code examples.
1. Function to create array
Code example:
import numpy as np
a = np.array([1, 2, 3])
print(a) # Output: [1 2 3]
b = np.array([[1, 2, 3], [4, 5, 6]])
print(b)
'''
Output:
[[1 2 3]
[4 5 6]]
'''
Code example:
import numpy as np
a = np.zeros((3, 3))
print(a)
'''
Output:
[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0 .]]
'''
Code example:
import numpy as np
a = np.ones((2, 2))
print(a)
'''
Output:
[[1. 1.]
[1. 1.]]
'''
2. Array operation functions
Code example:
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr.shape) # Output: (2, 3)
Code example:
import numpy as np
arr = np.array([1, 2, 3, 4, 5, 6])
res = arr.reshape((2, 3))
print(res)
'''
Output:
[[1 2 3]
[4 5 6]]
' ''
Code example:
import numpy as np
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]])
res = np.concatenate((a, b), axis=0)
print(res)
'''
Output:
[[1 2]
[3 4]
[5 6]]
'''
3. Functions for mathematical operations
Code example:
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4 , 5, 6])
res = np.add(a, b)
print(res) # Output: [5 7 9]
import numpy as np
b = np.array([1 , 2, 3])
res = np.subtract(a, b)
print(res) # Output: [3 3 3]
a = np.array([1, 2, 3])
res = np.dot(a, b)
print(res) # Output: 32
Conclusion:
Reference materials:
2. "Usage of Python Scientific Computing Library NumPy", https://www .runoob.com/numpy/numpy-tutorial.html
The above is the detailed content of Summary of numpy functions: List of commonly used functions and functions. For more information, please follow other related articles on the PHP Chinese website!