Hello. I have a list of float values like the following which are ids in my data and in the dataset they are originally like 11.0,11.2,16.2,… but when I try to put them in a Data object like the following:
data_with_id = Data(x=x_without_id, edge_index=edge_index.t().contiguous(),edge_weight=edge_feats,y=ground_truth_labels)
data_with_id.id_column = torch.tensor(id_column, dtype=torch.float)
I see torch.tensor changes the format of them to be like the following:
unique_values: {tensor(11.), tensor(11.2000), tensor(16.2000), tensor(6.1000), tensor(5006.), tensor(17.), tensor(13.2000), tensor(19.1000), tensor(2.), tensor(9.), tensor(5010.), tensor(6.), tensor(14.), tensor(14.1000), tensor(5001.), tensor(5.1000), tensor(6.2000), tensor(5001.), tensor(4.2000), tensor(11.1000), tensor(12.), tensor(5007.), tensor(17.1000), tensor(17.), tensor(4.1000), tensor(8.2000),tensor(19.1000)}
I tried to put them in a set to remove repeated values but still I see repeated values in it. Can anyone suggest me how can I handle it?
Here is the code I have tried so far:
missing_info = []
unique_values = set()
for i in range(start_timestep-1, start_timestep+ timestep-1):
if sequence[i].x.size(0) > 0:
np.set_printoptions(suppress=True)
id_column_tensor = torch.tensor(sequence[i].id_column)
id_column_list = [float(f"{value:.4f}") if isinstance(value, float) else value for value in id_column_tensor]
unique_values.update(id_column_list)
else:
raise ValueError(f"The tensor at sequence[{i}].x is empty.")
print('unique_values:',unique_values)
I have also a list and I want to check if any of the values within that list is not in unique_values, here is what I have tried but I see this code finds all the values are not in unique_values which is wrong!
for i in range(start_timestep-1, start_timestep+ timestep-1):
np.set_printoptions(suppress=True)
id_column_tensor = torch.tensor(sequence[i].id_column)
list_tensor = torch.tensor([float(f"{value:.4f}") if isinstance(value, float) else value for value in id_column_tensor])
for j in unique_values:
if not torch.isin(torch.tensor(j, dtype=list_tensor.dtype), list_tensor):
missing_info.append(j)