

X = tensor(rand(3,2,3)) Īdditionally, one can check for symmetry in tensors with the issymmetric function. W = tensor(rand(4,4,4)) Ī second argument can also be passed to symmetrize which specifies an array of modes with respect to which the tensor should be symmetrized. The new, symmetric tensor is formed by averaging over all elements in the tensor which are required to be equal. Symmetrizing and checking for symmetry in a tensorĪ tensor can be symmetrized in a collection of modes with the command symmetrize. Permute(X,1) %<- Call permute with *only* one dimension. X = tensor(1:4,4) %<- Create a 1-way tensor. Permuting a 1-dimensional tensor works correctly. Use permute to reorder the modes of a tensor X = tensor(1:24,) %<- Create a tensor. ans is a tensor of size 2 x 3 x 2Ĭ = tensor(floor(5*rand(2,3,2))) %<- Create another %<- Elementwise means for A, B, and C. ans is a tensor of size 2 x 3 x 2Ģ 2 %<- Max of A and B, elementwise. This can be used for any function that is not predefined for tensors. The function tenfun applies a specified function to a number of tensors. Using tenfun for elementwise operations on one or more tensors ans is a tensor of size 2 x 3 x 2Ī./B %<- Calls rdivide (but beware divides by zero!) ans is a tensor of size 2 x 3 x 2 ans is a tensor of size 2 x 3 x 2Ī./2 %<- Calls rdivide. ans is a tensor of size 2 x 3 x 2Ī.\B %<- Calls ldivide. ans is a tensor of size 2 x 3 x 2Ī.^2 %<- Calls power. ans is a tensor of size 2 x 3 x 2Ī.^B %<- Calls power. ans is a tensor of size 2 x 3 x 2ĥ*A %<- Calls mtimes. ans is a tensor of size 2 x 3 x 2Ī.*B %<- Calls times. ans is a tensor of size 2 x 3 x 2Ī-B %<- Calls minus. ans is a tensor of size 2 x 3 x 2Ī+B %<- Calls plus. ans is a tensor of size 2 x 3 x 2Ī<=B %<- Calls le.

ans is a tensor of size 2 x 3 x 2Īand checking for symmetry in a tensor.Use permute to reorder the modes of a tensor.Using tenfun for elementwise operations on one or more tensors.Basic operations (plus, minus, and, or, etc.) on a tensor.Using reshape to rearrange elements in a tensor.Computing the Frobenius norm of a tensor.Use find for subscripts of nonzero elements of a tensor.Use ndims and size to get the size of a tensor.Use double to convert a tensor to a (multidimensional) array.Use squeeze to remove singleton dimensions from a tensor.Use tenzeros to create a tensor of all zeros.

