astensor: Coercion to a tensor

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

Coerces a array to a tensor keeping dimension and names.

Usage

1
2
3
4
5
as.tensor(X,...)
## Default S3 method:
as.tensor(X,...,dims=NULL)
## S3 method for class 'tensor'
as.tensor(X,...)

Arguments

X

a multidimensional array

...

further generic arguments

dims

the new dim attribute to be used

Details

The main idea is that a multiway array like a vector or a matrix is nothing else than a tensor for R, but it still needs the tensor class be used with the tensorA library. However this is more a convenience function for migraters than a proper way construct a tensor, which is done by to.tensor.

Value

a tensor containing the same data as X

Note

You should typically use the to.tensor to generate a tensor, when you want to write vectorizable functions for tensors.

Author(s)

K. Gerald van den Boogaart

See Also

to.tensor

Examples

1
2
A <- diag(5)
as.tensor(A)

Example output

Attaching package: 'tensorA'

The following object is masked from 'package:base':

    norm

      I2
I1     [,1] [,2] [,3] [,4] [,5]
  [1,]    1    0    0    0    0
  [2,]    0    1    0    0    0
  [3,]    0    0    1    0    0
  [4,]    0    0    0    1    0
  [5,]    0    0    0    0    1
attr(,"class")
[1] "tensor" "matrix"

tensorA documentation built on Nov. 20, 2020, 9:07 a.m.

Related to astensor in tensorA...