Revision 4f00eb848c71c48550f574784bef1199132a8a17 authored by ParvaH on 07 November 2021, 12:36:28 UTC, committed by GitHub on 07 November 2021, 12:36:28 UTC
* Adding check for all modes fixed case and if true then to just return initialization in CP decomposition - part of issue 292 * Adding check for all modes fixed case and if true then to just return the initialization Co-authored-by: Parvathy <Parvathy>
1 parent ddc7958
plot_tensor.py
# -*- coding: utf-8 -*-
"""
Basic tensor operations
=======================
Example on how to use :mod:`tensorly` to perform basic tensor operations.
"""
import numpy as np
import tensorly as tl
from tensorly.testing import assert_array_equal
###########################################################################
# A tensor is simply a numpy array
tensor = tl.tensor(np.arange(24).reshape((3, 4, 2)))
print('* original tensor:\n{}'.format(tensor))
###########################################################################
# Unfolding a tensor is easy
for mode in range(tensor.ndim):
print('* mode-{} unfolding:\n{}'.format(mode, tl.unfold(tensor, mode)))
###########################################################################
# Re-folding the tensor is as easy:
for mode in range(tensor.ndim):
unfolding = tl.unfold(tensor, mode)
folded = tl.fold(unfolding, mode, tensor.shape)
assert_array_equal(folded, tensor)
Computing file changes ...