如何将1D数组与3D数组中的另一个数组相乘?

时间:2019-12-25 13:52:45

标签: python arrays function multidimensional-array

我有一个1D数组,我只想将其与3D数组的第一个轴相乘。

例如,我的1D数组的长度为710,我想乘以同样长为710的3D数组的第一个轴。我不希望它乘以其他两个轴(因为它们的大小不同,我得到一个错误)。

我该怎么做?

下面是示例代码:

    data = sla_standard[:,:,:]
    window = w

    print(window.shape)
    print(data.shape)

    #GOAL: multiply the window with the first axis of my data array

    what is printed from console: 
    (710,)
    (710, 81, 320)

1 个答案:

答案 0 :(得分:1)

两个数组都应具有相同的维度(即应为3D)。否则,轴将自动匹配。使用BEGIN { ss = "," # Start blacklist. } NR==FNR { # Only true for first file in list (blacklist). ss = ss""$1"," # Extend blacklist. next # Go get next line. } ss !~ ","$18"," { # Only get here for second file (input). print } 将其投射到3D:

window[:, None, None]