python - Creating matrix by multiply columns -
i want create matrix shown @ picture: creating new matrices multiplying columns of matrix in elementwise
is possible create without using 3 loop?
it bit hard verify without actual input , desired output data, can use numpy reshaping , broadcasting operation without loops:
a = numpy.arange(3 * 6).reshape(3, 6) b = numpy.arange(3 * 3).reshape(3, 3) c = numpy.arange(3 * 2).reshape(3, 2) x = a.reshape(3, 3, 2).transpose(1, 0, 2) * b[..., none] y = a.reshape(3, 3, 2).transpose(0, 2, 1) * c[..., none]
Comments
Post a Comment