I have three separate matrix of x,y,z; all having size of 261*602, I want to combine them into a single matrix so that I can make a 3D plot from it, for example:
x11 | x12 | x13 |
---|---|---|
x21 | x22 | x23 |
x31 | x32 | x33 |
y11 | y12 | y13 |
---|---|---|
y21 | y22 | y23 |
y31 | y32 | y33 |
z11 | z12 | z13 |
---|---|---|
z21 | z22 | z23 |
z31 | z32 | z33 |
combine into:
x11,y11,z11 | x12,y12,z12 | x13,y13,z13 |
---|---|---|
x21,y21,z21 | x22, y22,z22 | x23,y23,z23 |
x31,y31,z31 | x32,y32,z32 | x33,y33,z33 |
Is there any simple way to do that? I have tried it on Origin Lab but it doesn't work.
CodePudding user response:
You can use numpy
to do element-wise multiplication, along with other common linear algebra operations.
>>> import numpy as np
>>> a = np.arange(9).reshape((3,3))
>>> a
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>> b = np.arange(9).reshape((3,3))
>>> c = np.arange(9).reshape((3,3))
>>> a * b * c
array([[ 0, 1, 8],
[ 27, 64, 125],
[216, 343, 512]])
CodePudding user response:
If you want to perform element-wise multiplication of several arrays, you can take advantage of the reduce
version of numpy.multiply
:
lst = [a, b, c]
out = np.multiply.reduce(lst)
example output:
array([[ 0, 6, 24],
[ 60, 120, 210],
[336, 504, 720]])
used input:
a = np.arange(9).reshape((3,3))
b = a 1
c = a 2