@@ -43,11 +43,11 @@ def __init__(self, size, *args):
4343 or two sorted lists containing indices and values.
4444
4545 >>> print SparseVector(4, {1: 1.0, 3: 5.5})
46- [1: 1.0, 3: 5.5]
46+ (4,[1,3],[ 1.0,5.5])
4747 >>> print SparseVector(4, [(1, 1.0), (3, 5.5)])
48- [1: 1.0, 3: 5.5]
48+ (4,[1,3],[ 1.0,5.5])
4949 >>> print SparseVector(4, [1, 3], [1.0, 5.5])
50- [1: 1.0, 3: 5.5]
50+ (4,[1,3],[ 1.0,5.5])
5151 """
5252 assert type (size ) == int , "first argument must be an int"
5353 self .size = size
@@ -161,10 +161,9 @@ def squared_distance(self, other):
161161 return result
162162
163163 def __str__ (self ):
164- inds = self .indices
165- vals = self .values
166- entries = ", " .join (["{0}: {1}" .format (inds [i ], vals [i ]) for i in xrange (len (inds ))])
167- return "[" + entries + "]"
164+ inds = "[" + "," .join ([str (i ) for i in self .indices ]) + "]"
165+ vals = "[" + "," .join ([str (v ) for v in self .values ]) + "]"
166+ return "(" + "," .join ((str (self .size ), inds , vals )) + ")"
168167
169168 def __repr__ (self ):
170169 inds = self .indices
@@ -215,11 +214,11 @@ def sparse(size, *args):
215214 or two sorted lists containing indices and values.
216215
217216 >>> print Vectors.sparse(4, {1: 1.0, 3: 5.5})
218- [1: 1.0, 3: 5.5]
217+ (4,[1,3],[ 1.0,5.5])
219218 >>> print Vectors.sparse(4, [(1, 1.0), (3, 5.5)])
220- [1: 1.0, 3: 5.5]
219+ (4,[1,3],[ 1.0,5.5])
221220 >>> print Vectors.sparse(4, [1, 3], [1.0, 5.5])
222- [1: 1.0, 3: 5.5]
221+ (4,[1,3],[ 1.0,5.5])
223222 """
224223 return SparseVector (size , * args )
225224
0 commit comments