How to make dataset to train the Multitasking learning?

i want to train a Multitasking network ,and the data need two is a 2D np.ndarray,another is a onehot label to appoint the kind of the input.So how could i make the dataset?One input could have two different labels?

You could create a Dataset and return your appropriate targets.
I used a tensor for the 2D target instead of a numpy.array.
You can easily transform it to a tensor using:

target1 = torch.from_numpy(arr)

Also, I created the second target as a tensor containing class indices. The loss functions for classification need an index tensor instead of a one-hot encoded tensor.
Here is a small example:

class MyDataset(Dataset):
    def __init__(self, data, target1, target2): = data
        self.target1 = target1
        self.target2 = target2
    def __getitem__(self, index):
        x =[index]
        y1 = self.target1[index]
        y2 = self.target2[index]
        return x, y1, y2
    def __len__(self):
        return len(
data = torch.randn(100, 3, 24, 24)
target1 = torch.randn(100, 10, 10) # your 2d tensor
target2 = torch.empty(100, dtype=torch.long).random_(10) # 10 class indices
dataset = MyDataset(data, target1, target2)

x, y1, y2 = dataset[0]