美文网首页
5.3数组运算

5.3数组运算

作者: 云殊_Tech | 来源:发表于2020-12-12 00:01 被阅读0次
  1. slice



  2. 改变数组的形状

    • obj.reshape(shape): return a new ndarray

    • obj.resize(shape): changing the shape in place

      • 改变形状时应保持数组元素总数一致
    • e.g. b.reshape(-1,1): 参数-1表示根据数组元素总数和其他维度的取值,自动计算该维度的取值

  3. 数组间的运算

    • 加法


  • elementwise multiplication
    A * B

  • matrix multiplication
    A @ B
    np.dot(A,B)
    np.matmul(A,B)

  • transpose
    np.transpose(A)

  • inverse
    np.linalg.inv(A)

  1. 数组元素间的运算

    • np.sum() 所有元素求和
    • np.prod() 所有元素乘积
    • np.diff() 计算数组的相邻元素之间的差
    • np.sqrt()
    • np.exp()
    • np.abs()
  2. 按行求和 & 按列求和


  1. 数组堆叠运算
    np.stack((arr1,arr2,...),axis)

相关文章

网友评论

      本文标题:5.3数组运算

      本文链接:https://www.haomeiwen.com/subject/amosgktx.html