np.maximum

np.maximum既可以处理相同维度的向量,又可以处理不同维度的

import numpy as np

if __name__ == '__main__':
    X = np.array([1, 2, 3, 4])
    Y = np.array([4, 3, 1, 3])
    print(np.maximum(X, Y))

    X = np.array([1, 2, 3, 4])
    Y = np.array([2])
    print(np.maximum(X, Y))
[4 3 3 4]
[2 2 3 4]
文章目录