I have created a class called Tensor
import numpy as np
class Tensor:
def __init__(self, data):
self.data = np.array(data)
and I'd like to set elements of a numpy array using Tensor:
x = np.array([[1,2,3,4],[4,3,2,1]])
x[:,::2] = Tensor([[0,0],[1,1]])
but it results an error ValueError: setting an array element with a sequence.
one workaround is to retrieve Tensor's data attribute: x[:,::2] = Tensor([[0,0],[1,1]]).data, but I'd like to know how to do it without manually retrieving anything, like when you can set values with a list or numpy array: x[:,::2] = [[0,0],[1,1]] or x[:,::2] = np.array([[0,0],[1,1]])