I am trying to multiply part of a column vector (n,1) by a part of another row vector (1,n). Both parts have the same length. So I should get a matrix (n,n).
Here is my simple code:
PROGRAM test_pack_1
REAL :: m(1,10), x(10,1), y(10,10)
m = reshape( (/ 1, -1, 3, 2, 1, 2, -2, -2, 1, 0 /), (/ 1, 10 /))
x = reshape( (/ 1, 0, 1, 1, 0, 1, 1, 0, 1, 0 /), (/ 10, 1 /))
y(1:9,1:9) = MATMUL(x(1:9,1),m(1,1:9))
DO j = 1,10
PRINT* ;WRITE(*,*) y(:,j)
ENDDO
print *
END PROGRAM
I'm Using:
ifort -g -debug -traceback -check all -ftrapuv test_cshift.f90
And I'm getting:
test_cshift.f90(7): error #6241: The shapes of the arguments are inconsistent or nonconformable. [MATMUL]
y(1:9,1:9) = MATMUL(x(1:9,1),m(1,1:9))
-------------^
test_cshift.f90(7): error #6366: The shapes of the array expressions do not conform. [Y]
y(1:9,1:9) = MATMUL(x(1:9,1),m(1,1:9))
MatMul operation takes two tensors and performs usual matrix-matrix multiplication, matrix-vector multiplication or vector-matrix multiplication depending on argument shapes. Input tensors can have any rank >= 1.
The numpy. matmul() function returns the matrix product of two arrays. While it returns a normal product for 2-D arrays, if dimensions of either argument is >2, it is treated as a stack of matrices residing in the last two indexes and is broadcast accordingly.
In mathematics, Vector multiplication refers to one of several techniques for the multiplication of two (or more) vectors with themselves. It may concern any of the following articles: Dot product – also known as the "scalar product", a binary operation that takes two vectors and returns a scalar quantity.
In Julia, we can do matrix multiplication on two variables with a Matrix data type. We can use the asterisk ( * ) operator for this purpose.
The problem is that x(1:9,1)
isn't of shape [9 1]
but [9]
. You need to use x(1:9, 1:1)
. The same goes for m
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With