【问题标题】:Infinity norm for each row of numpy array每行numpy数组的无穷范数
【发布时间】:2021-04-27 19:59:15
【问题描述】:

我有一个 numpy 数组:

t1 = np.arange(12).reshape(3,4)

我需要找到数组每一行的 L-infinity norm,并返回具有最小 L-infinity norm 的行索引。

我正在尝试这个来找到每一行的范数:

rest1 = LA.norm(t1, ord='inf', axis=1)

但我不断收到以下错误:

raise ValueError(f"向量的无效范数顺序 '{ord}'") ValueError:向量的范数顺序“inf”无效

大家能否建议我如何做到这一点?非常感谢!

【问题讨论】:

    标签: python numpy matrix linear-algebra


    【解决方案1】:
    import numpy as np
    t1 = np.arange(12).reshape(3,4)
    rest1 = np.linalg.norm(t1, ord=np.inf, axis=1)
    # >>> array([ 3.,  7., 11.])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-12
      • 1970-01-01
      • 2020-06-23
      • 2020-01-29
      • 2017-09-23
      • 2017-07-22
      • 2022-12-12
      相关资源
      最近更新 更多