Question: This is my matrix vector multiplication - i want to see how the values get multiplied.. can you use pen and paper to show how

This is my matrix vector multiplication-
i want to see how the values get multiplied.. can you use pen and paper to show how the matrix and vector gets multiplied using the logic given below? Like how the row of one matrix and the column of the other matrix gets joined and multiplied? please work it out and show me . Thank you so much
import org.apache.spark.sql.types._
import org.apache.spark.sql.functions._
// Define matrix and vector data as sequences
val matrix_xSeq = Seq(
(0,0,1.0),(0,1,2.0),
(1,0,3.0),(1,1,4.0)
)
val vector_ySeq = Seq(
(0,5.0),
(1,6.0),
)
// Convert matrix and vector data to DataFrames
val matrix_xDF = matrix_xSeq.toDF("row", "col", "val")
val vector_yDF = vector_ySeq.toDF("row", "val")
// Show DataFrames
matrix_xDF.show
vector_yDF.show
matrix_xDF.createOrReplaceTempView("X")
vector_yDF.createOrReplaceTempView("Y")
val resultDF = spark.sql("""
SELECT X.row, SUM(X.val * Y.val) AS val
FROM X
JOIN Y ON X.col = Y.row
GROUP BY X.row
""")
resultDF.show

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!