Learn R Programming

tensorA (version 0.36.2.1)

diagmul.tensor: Multiplication of a tensor with a tensor given by its diagonal

Description

This is a convenience function for scaling elements of a tensor with different numbers based on their position in the tensor.

Usage

diagmul.tensor(X,i=names(D),D,j=i,by=NULL)

Value

A tensor with the shape and dimensions as X with entries

\(X_{ik}\) scaled by \(D_im\), where \(i\) and

\(k\) can represent multi-indices.

Arguments

X

The tensor to be scaled

D

A tensor containing scaling constants

i

numeric of character vector giving the dimensions of X to be used for the product.

j

numeric of character vector giving the dimensions of D to be used for the product.

by

Every operation is parallel for all levels of by in X and/or D.

Author

K. Gerald van den Boogaart

Details

Let $$X_{i_1\ldots i_d k_1 \ldots k_d}$$ and $$D_{j_1\ldots j_d}$$ than the result is: $$E_{i_1\ldots i_d k_1 \ldots k_d}=X_{i_1\ldots i_d k_1 \ldots k_d}D_{j_1\ldots j_d}$$

See Also

to.tensor

Examples

Run this code
(A <- matrix(rep(1:3,each=3),nrow=3))
(b <- to.tensor(c(1,1/2,1/3)))
diagmul.tensor(as.tensor(A),2,as.tensor(c(1,1/2,1/3)),1)
diagmul.tensor(as.tensor(A),1,as.tensor(c(1,1/2,1/3)),1)
A %*% diag(b)
diag(b) %*% A

Run the code above in your browser using DataLab