Mercurial > pylearn
comparison lookup_list.py @ 110:8fa1ef2411a0
Worked on OneShotTLearner and implementation of LinearRegression
author | bengioy@bengiomac.local |
---|---|
date | Tue, 06 May 2008 22:24:55 -0400 |
parents | 427e02ef0629 |
children | b4657441dd65 ff6b7bfb6cdc |
comparison
equal
deleted
inserted
replaced
109:d97f6fe6bdf9 | 110:8fa1ef2411a0 |
---|---|
7 a dictionary the order of the elements depends not on their key but | 7 a dictionary the order of the elements depends not on their key but |
8 on the order given by the user through construction) so that | 8 on the order given by the user through construction) so that |
9 following syntactic constructions work as one would expect: | 9 following syntactic constructions work as one would expect: |
10 example = LookupList(['x','y','z'],[1,2,3]) | 10 example = LookupList(['x','y','z'],[1,2,3]) |
11 example['x'] = [1, 2, 3] # set or change a field | 11 example['x'] = [1, 2, 3] # set or change a field |
12 print example('z','y') # prints [3,2] | |
12 x, y, z = example | 13 x, y, z = example |
13 x = example[0] | 14 x = example[0] |
14 x = example["x"] | 15 x = example["x"] |
15 print example.keys() # prints ['x','y','z'] | 16 print example.keys() # prints ['x','y','z'] |
16 print example.values() # prints [[1,2,3],2,3] | 17 print example.values() # prints [[1,2,3],2,3] |
86 new_example = deepcopy(lhs) | 87 new_example = deepcopy(lhs) |
87 for item in self.items(): | 88 for item in self.items(): |
88 new_example.append_keyval(item[0],item[1]) | 89 new_example.append_keyval(item[0],item[1]) |
89 return new_example | 90 return new_example |
90 | 91 |
91 | |
92 def __eq__(self, other): | 92 def __eq__(self, other): |
93 return self._values==other._values and self._name2index==other._name2index and self._names==other._names | 93 return self._values==other._values and self._name2index==other._name2index and self._names==other._names |
94 | 94 |
95 def __ne__(self, other): | 95 def __ne__(self, other): |
96 return not self.__eq__(other) | 96 return not self.__eq__(other) |
97 | 97 |
98 def __hash__(): | 98 def __hash__(): |
99 raise NotImplementedError() | 99 raise NotImplementedError() |
100 | |
101 def __call__(*names): | |
102 """ | |
103 Return a list of values associated with the given names (which must all be keys of the lookup list). | |
104 """ | |
105 return [self[name] for name in names] |