r - How to deal with "non-conformable" arrays? -
r - How to deal with "non-conformable" arrays? -
how 1 element-wise arithmetic operations 2 arrays conformable in first dimensions 1 has dimension?
example, multiply array a
(3 x 3 x 2) array b
(3 x 3):
a <- array(1:18, dim=c(3,3,2)) b <- diag(3)
the next fails because arrays non-conformable.
> * b
for work, have cast array b
array right number of dimensions.
> * array(b, dim=c(3,3,2))
this doesn't strike me beingness straightforward , i'm sure there must simpler way.
you can try:
a * c(b)
c
strip attributes, allow recycling of b
simple vector , lead believe desired outcome:
, , 1 [,1] [,2] [,3] [1,] 1 0 0 [2,] 0 5 0 [3,] 0 0 9 , , 2 [,1] [,2] [,3] [1,] 10 0 0 [2,] 0 14 0 [3,] 0 0 18
arrays r multidimensional-array
Comments
Post a Comment