0

I am fairly new to Breeze library. I am trying to convert a 3D Array of shape (2,1,40) to a dense matrix but I am not sure if I am doing it the right way. My requirement is:

A matrix with 2 rows, 1 column and each of the two rows should have 0.0 values (40 times)

import breeze.linalg._

val matrix = new DenseMatrix[Float](shape(0), shape(1), Array.fill(shape(2))(0.0f))
Dennis Tsoi
  • 1,349
  • 2
  • 11
  • 17
Rahul Kumar
  • 87
  • 1
  • 12

1 Answers1

1

If you are looking for direct support for higher-order tensors, bad luck. David Hall already stated that they would require a lot of work to implement properly which makes perfect sense. They are very math intensive.

With that said you can still make a 2 by 1 DenseMatrix of DenseVectors and manipulate the values of those vectors. 2 by 1 matrix is basically a vector so here's example with 2 by 2 and "40 zeroes" vectors

val matrix = DenseMatrix( 
  (DenseVector.zeros[Double](40), DenseVector.zeros[Double](40)), 
  (DenseVector.zeros[Double](40), DenseVector.zeros[Double](40)) 
)

matrix(0,0)(0) = 1.0

println( matrix(0,0) )

I must say that this approach is not recommended due to complex nature of computations on such data structure. If you are working with points in 3D space I would rather go for either a matrix or distributed dataset of vectors.

Dennis Tsoi
  • 1,349
  • 2
  • 11
  • 17