Numpy Arrays M Dimentions Elementwise Multiplication

时间:2017-09-13 16:21:13

标签: python arrays numpy

问题解释

我有四个numpy数组

n维的A

m维的B

o of dimements

n维的D

我还有每个维度的indexex列表

Aindexes = Ia[Ia1, Ia2, … , Ian]

Bindexes = Ib[Ib1,Ib2, …. , Ibm]

Cindexes = Ic[Ia1, Ic1, Ic2,  …. , Ico]

Dindexes = Ia[Ia1, Ia2, … Ian]

需要执行三个操作,但我需要它根据索引的匹配行为不同:

R = A * B  (all different indexes) =
RIndexes [Ia1, Ia2, … , Ian, Ib1, Ib2, … Ibm] 
Rvalues it’s an elementwise multiplication of all elements

R = A * C (Some indexes equal)
RIndexes [Ia1, Ia2, … Iam, Ic1, Ic2, … Ico]
Rvalues it’s an elementwise multiplication of all elements not repeating the indexes that are equal 

R = A * D (all equal indexes) 
Rindexes [Ia1, Ia2, … Iam] 
Rvalues = A[Iam] * D[Iamij]

2维表格的实际例子

A [Index1[3],Index2[2]] = [[1,2],[1,2],[1,2]]

B [Index4[3], Index3[2]] = [[3,4],[3,4],[3,4]]

C [Index1[3], Index3[2]] = [[3,4],[3,4],[3,4]]

D[Index1[3],Index2[2]] = [[3,4],[3,4],[3,4]]

A * B

通过某些索引进行评估

R[Index1[3],Index2[2 = 1],Index4[3],Index3[2 = 1]] = [[3,3,3],[3,3,3],[3,3,3]]

R[Index1[3],Index2[2 = 2],Index4[3],Index3[2 = 1]] = [[6,6,6],[6,6,6],[6,6,6]]

R[Index1[3],Index2[2 = 1],Index4[3],Index3[2 = 2]] = [[4,4,4],[4,4,4],[4,4,4]]

R[Index1[3],Index2[2 = 2],Index4[3],Index3[2 = 2]] = [[8,8,8],[8,8,8],[8,8,8]]

RIndex1[3],Index2[2],Index4[3],Index3[2]] = [[[[3,3,3],[3,3,3],[3,3,3]],[[4,4,4],[4,4,4],[4,4,4]]],[[[6,6,6],[6,6,6],[6,6,6]],[[[8,8,8],[8,8,8],[8,8,8]]]]]

:一种* C

通过某些索引进行评估

R[Index1[3],Index2[2],Index3[2 = 1]] = [[3,6],[3,6],[3,6]]

R[Index1[3],Index2[2],Index3[2 = 2]] = [[4,8],[4,8],[4,8]]

R[Index1[3],Index2[2],Index3[2]] = [[[3,6],[3,6],[3,6]]
,[[4,8],[4,8],[4,8]]]

A * d

R[Index1[3],Index2[2]] = [[1,4],[1,4],[1,4]]

我的问题是如何使用numpy实现m维度?

0 个答案:

没有答案