73 return (tensor - mean) / torch.sqrt(variance + 1e-4)
74
75 normed_weights = torch.nn.functional.softmax(
76 torch.cat([parameter for parameter in self.scalar_parameters]), dim=077 )
78 normed_weights = torch.split(normed_weights, split_size_or_sections=1)
79
It is unnecessary to use a comprehension just to loop over the iterable
and create a list
/set
/dict
out of it.
Python has a specialized set of tools for this task: the list
/set
/dict
constructors, which are faster and more readable.
states = [
('AL', 'Alabama'),
('AK', 'Alaska'),
('AZ', 'Arizona'),
('AR', 'Arkansas'),
('CA', 'California'),
# ...
]
abbreviations_to_names = {
abbreviation: name
for abbreviation, name in states
}
states = [
('AL', 'Alabama'),
('AK', 'Alaska'),
('AZ', 'Arizona'),
('AR', 'Arkansas'),
('CA', 'California'),
# ...
]
abbreviations_to_names = dict(states)