numpy generic functions: fast element-wise array functions

A universal function, also known as ufunc, is a function that performs element-wise operations on ndarray data. Some simple functions accept one or more scalar values ​​and produce one
or more scalar results, and general functions are vectorized wrappers for these simple functions.

There are many ufuncs that are simple element-wise transformations, such as sqrt and exp functions: unary universal functions

import numpy as np
数组 = np.arange(10)
print(数组)
print(np.sqrt(数组)) # 返回正的平方根
print(np.exp(数组)) # 计算每个元素的自然指数值e的x次方

Introduce binary universal functions: for example, add and maximum will accept two arrays and return the end result of an array, so they are called binary universal functions.

import numpy as np
x = np.random.randn(8)
y = np.random.randn(8)
print(x)
print('--------')
print(y)
print('--------')
print(np.maximum(x ,y)) # 对位比较大小,取大的,生成新的数组返回,逐个元素地将 x和 y 中元素的最大值计算出来

insert image description here
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/m0_66106755/article/details/128725396