How to create dataset with multiple input/output features

Hi, I am new to pytorch and pandas. I come from a Matlab background.

I am trying to import a dataset in python from a .csv file and it should be quite straightforward. My .csv contains a bunch of columns (19), some of them are input features and some are output features.

What I do is the following, how can I extend this code to import multiple input and output features?

# Load the data
D = pd.read_csv("result_reorganized.csv")

x_dataset = torch.tensor(D.inputFeature1.values, dtype=torch.float)
y_dataset = torch.tensor(D.outputFeature1.values, dtype=torch.float)

In matlab I would do something like

[ x1_dataset, x2_dataset, x3_dataset] = [torch.tensor(D.inputFeature1.values, dtype=torch.float) , torch.tensor(D.inputFeature2.values, dtype=torch.float), torch.tensor(D.inputFeature3.values, dtype=torch.float)]

I can’t find so far how to do this in python/pandas.
Thanks for your help,
Fabrizio.

I thought that I found my answer:

x1_dataset = torch.tensor(D.inputFeature1.values, dtype=torch.float)

x2_dataset = torch.tensor(D.inputFeature2.values, dtype=torch.float)

x3_dataset = torch.tensor(D.inputFeature3.values, dtype=torch.float)

x_dataset = [x1_dataset, x2_dataset, x3_dataset]

However, in this way x_dataset is of type list while I would like to have a type tensor

Could you help me?

maybe try using torch.cat (http://pytorch.org/docs/torch.html#torch.cat)
or torch.stack

see: How to concatenate list of pytorch tensors?

1 Like

Thanks it works!

My code now is the following (hopefully it will help some other newbies like me)

x1_dataset = torch.tensor(D.inputFeature1.values, dtype=torch.float)

x2_dataset = torch.tensor(D.inputFeature2.values, dtype=torch.float)

x3_dataset = torch.tensor(D.inputFeature3.values, dtype=torch.float)

x_dataset = torch.stack([x1_dataset, x2_dataset, x3_dataset])