Cytnx icon indicating copy to clipboard operation
Cytnx copied to clipboard

Inherit the labels when slicing a UniTensor

Open chiamin opened this issue 1 year ago • 0 comments

So far if one get a UniTensor from slicing another UniTensor, the labels will be default values '0', '1', ..., as can be seen in the following code.

import cytnx
import numpy as np

def toUniTen (T):
    assert type(T) == np.ndarray
    T = cytnx.from_numpy(T)
    return cytnx.UniTensor (T)

a = np.random.rand(2,2,2)
t = toUniTen(a)
t.set_labels(['i','j','k'])
print(t.labels())
b = t[:,0,:]
print(b)
print(b.labels())

I recommend inheriting the labels from the mother tensor.

chiamin avatar Feb 21 '24 04:02 chiamin