1 条题解

  • 0
    @ 2026-3-26 15:56:15

    NUMPY084 题解:计算外积

    题目

    计算两个数组的外积。

    解题思路

    1. 读取两个数组
    2. 使用 np.outer\texttt{np.outer} 计算外积

    代码

    import numpy as np
    
    n, m = map(int, input().split())
    A = np.array(list(map(int, input().split())))
    B = np.array(list(map(int, input().split())))
    result = np.outer(A, B)
    print(result)
    

    代码详解

    外积公式:

    Ci,j=Ai×BjC_{i,j} = A_i \times B_j

    运行示例

    输入:

    3 2
    1 2 3
    4 5
    

    分析:

    • C0,0=1×4=4C_{0,0} = 1 \times 4 = 4
    • C0,1=1×5=5C_{0,1} = 1 \times 5 = 5
    • C1,0=2×4=8C_{1,0} = 2 \times 4 = 8
    • 以此类推...

    输出:

    [[ 4  5]
     [ 8 10]
     [12 15]]
    

    核心知识点

    1. np.outer\texttt{np.outer} —— 计算外积
    • 1

    信息

    ID
    222
    时间
    1000ms
    内存
    256MiB
    难度
    (无)
    标签
    (无)
    递交数
    0
    已通过
    0
    上传者