Complete list of commonly used functions in the Numpy library: unlocking efficient scientific computing skills
For scientific computing in Python, the Numpy library is an essential tool, which provides a variety of functions Powerful functions and other useful tools. In order to help readers make better use of the Numpy library, this article will introduce some commonly used Numpy functions, as well as their usage and examples.
Example:
import numpy as np # 从 Python 列表和元组创建数组 arr1 = np.array([1, 2, 3, 4, 5]) arr2 = np.array((1, 2, 3)) # 创建全 0 数组 zeros_arr = np.zeros((2, 3)) # 创建全 1 数组 ones_arr = np.ones((2, 3)) # 创建一个任意值的数组 full_arr = np.full((2, 3), 4) # 创建一个类似于 Python range 函数的数组 range_arr = np.arange(0, 10, 2) # 创建一个在指定间隔内的数组 linspace_arr = np.linspace(0, 1, 5)
import numpy as np arr1 = np.array([1, 2, 3]) arr2 = np.array([4, 5, 6]) # 两个数组的加法 add_arr = np.add(arr1, arr2) # 两个数组的减法 sub_arr = np.subtract(arr1, arr2) # 两个数组的乘法 mul_arr = np.multiply(arr1, arr2) # 两个数组的除法 div_arr = np.divide(arr1, arr2) # 将一组数按照指定的次数幂进行计算 power_arr = np.power(arr1, 2) # 对每个元素求开方 sqrt_arr = np.sqrt(arr2)
import numpy as np arr = np.array([[1, 2], [3, 4], [5, 6]]) # 交换数组的轴 transpose_arr = np.transpose(arr) # 重新定义数组形状 reshape_arr = np.reshape(arr, (2, 3)) # 对多个数组进行拼接 arr1 = np.array([1, 2, 3]) arr2 = np.array([4, 5, 6]) concat_arr = np.concatenate((arr1, arr2), axis=0) # 将一个数组分裂成多个数组 split_arr = np.split(concat_arr, 2) # 按照指定要求进行数组排序 sort_arr = np.sort(arr1)
import numpy as np arr = np.array([1, 2, 3, 4, 5, 6]) # 对数组进行求和计算 sum_arr = np.sum(arr) # 对数组进行求平均数计算 mean_arr = np.mean(arr) # 对数组进行求标准差计算 std_arr = np.std(arr) # 对数组进行求方差计算 var_arr = np.var(arr) # 对数组进行求最大值计算 max_arr = np.max(arr) # 对数组进行求最小值计算 min_arr = np.min(arr)
The above is the detailed content of Comprehensive collection of commonly used functions in the Numpy library: unlocking efficient scientific computing techniques. For more information, please follow other related articles on the PHP Chinese website!