Re: [Tutor] An -1.#IND error
Luke: This is literally the core of the code: A = scipy.asmatrix(scipy.zeros((M, N), float)) q = scipy.asmatrix(scipy.zeros((N, 1)), float) b = scipy.asmatrix(scipy.zeros((1, N)), float) # populate A # x is a vector of valid floats (I've checked) # calculate b as: b = A * x After the matrix multiplication, the b vector elements are all "-1.#IND" 's. Note that there are no divisions by zero in the program. Cheers Dinesh - Original Message - From: Luke Paireepinart To: Dinesh B Vadhia Cc: tutor@python.org Sent: Saturday, January 26, 2008 11:12 PM Subject: Re: [Tutor] An -1.#IND error Dinesh B Vadhia wrote: > After a matrix*vector multiplication (ie. b = Ax, with A, x and b all > floats), the b vector elements are all "-1.#IND". What does this > mean? Btw, they are no divisions in the program eg. no divide by zeros. A code sample would be _much_ more helpful here. Please include one that exhibits the problem. > > Dinesh > > > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] conditionals with slicing not seeming to work
Rob Stevenson wrote: > the intention of this snippet is to only print slices where character 1 > is lower case, 2-4 and 6-8 are upper. The logic here looks right to a > VB eye. > for i in h: > j=s[i:i+8] > if j[0].islower(): > if j[1:3].isupper(): > if j[5:7].isupper(): > print j > > Any help much appreciated! If you want the second character through the fourth (three characters), use j[1:4]. Slices include the first index, not the second - they are 'up to but not including' the end index. Likewise j[5:8] would be the sixth through eigth characters. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] conditionals with slicing not seeming to work
- Jeff Younker - [EMAIL PROTECTED] - On Jan 27, 2008, at 3:01 PM, Rob Stevenson wrote: I'm working at a certain website's puzzles using pythonin order to learn the language, but am stuck understanding what is going on in my code (ie why it doesn't do as expected) the intention of this snippet is to only print slices where character 1 is lower case, 2-4 and 6-8 are upper. The logic here looks right to a VB eye. Here's the code... s = """kKjyaqbooOlNkAddgAazFlgKLjlXDGtlvRBYCYQiRfRIfWIYaLZxLrQzrYzBghYOKAaKgXmUpPkCaMmN GlAXokgPsdyUjsiaKSSoeCqMrMbQXeRZqkNeAQpujYJFGfbeceunpFNYjuUPiQVOZPXTKhiwPMLKZEKP NoEPPwXtRoVfGYIRyRgZWyJrMjuBQNchjZBNQUwSgIyXniXCMeXRfAcDKxskxYvMyRGyXeSlOFKFItyI wgDEIuvHFxRfQhtqLKnJfONtkcnDORkZqbtPplsjjTEIsquhSsQTwNZuPVxaTqDvwMONBfCsNJuJpJHZ dCdFLtBQPtFQuCdKOrpndJNUFQIDSbetUKylhSUjcDVtbiQrWMRQhAwGUZyPneCGUjGBBTkLqxLAXXtB KfErkDaWMFZZeuqDmXKJEGHyToPUhPphfVhgUZgbIuRAtWnroImpJKqqmEZqeNQCKzhjIkKQHURWLXFw PBuijeoTSpsVLaOGuLVjMZXkBvVXwUuHfBihziiavGSYofPNeKsTXruMUumRRPQJzvSzJkKbtSipiqBd """ h = range(len(s)-9) for i in h: j=s[i:i+8] if j[0].islower(): if j[1:3].isupper(): if j[5:7].isupper(): print j Any help much appreciated! Your slice indexes are off: >>> m = "01234567" >>> m[0] '0' >>> m[1:3] '12' >>> m[5:7] '56' >>> What you want is: >>> m[2:4] '23' >>> m[6:8] '67' -jeff ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] conditionals with slicing not seeming to work
Hello, I'm working at a certain website's puzzles using pythonin order to learn the language, but am stuck understanding what is going on in my code (ie why it doesn't do as expected) the intention of this snippet is to only print slices where character 1 is lower case, 2-4 and 6-8 are upper. The logic here looks right to a VB eye. Here's the code... s="""kKjyaqbooOlNkAddgAazFlgKLjlXDGtlvRBYCYQiRfRIfWIYaLZxLrQzrYzBghYOKAaKgXmUpPkCaMmN GlAXokgPsdyUjsiaKSSoeCqMrMbQXeRZqkNeAQpujYJFGfbeceunpFNYjuUPiQVOZPXTKhiwPMLKZEKP NoEPPwXtRoVfGYIRyRgZWyJrMjuBQNchjZBNQUwSgIyXniXCMeXRfAcDKxskxYvMyRGyXeSlOFKFItyI wgDEIuvHFxRfQhtqLKnJfONtkcnDORkZqbtPplsjjTEIsquhSsQTwNZuPVxaTqDvwMONBfCsNJuJpJHZ dCdFLtBQPtFQuCdKOrpndJNUFQIDSbetUKylhSUjcDVtbiQrWMRQhAwGUZyPneCGUjGBBTkLqxLAXXtB KfErkDaWMFZZeuqDmXKJEGHyToPUhPphfVhgUZgbIuRAtWnroImpJKqqmEZqeNQCKzhjIkKQHURWLXFw PBuijeoTSpsVLaOGuLVjMZXkBvVXwUuHfBihziiavGSYofPNeKsTXruMUumRRPQJzvSzJkKbtSipiqBd""" h = range(len(s)-9) for i in h: j=s[i:i+8] if j[0].islower(): if j[1:3].isupper(): if j[5:7].isupper(): print j Any help much appreciated! Rob ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] setstate trouble when unpickling
I load a "cellule" with self.cellule=pickle.load(prjfile) Within the class "cellule" I use this method to add an attribute "note" ,with success: def __setstate__(self, state): #20080127 ajoute note if 'note' not in state: self.note="***" self.__dict__.update(state) self.note="***" is the new attribute in __init__ I checked with a debug: after the pickle.load the class instance is created without the attribute "note". The method __setstate__ is called and the new attribute is added. With python 2.5.1 Robert Jeff Peery-2 wrote: > > Hello, > > I've got a fairly simple class instance that I'm pickling. I'm using > setstate to update the instance when I unpickle. Although the setstate > doesn't seem to be called upon unpickling... here's an example, if anyone > see's what I'm doing wrong, please let me know. Thanks! > > so I say start out with this class: > > class dog: > def __init__(self): > self.num_legs = 4 > > then I pickle the instance of: > sparky = dog() > > then I update my dog class to: > class dog: > def __init__(self): > self.hair_color = 'brown' > self.num_legs = 4 > > def __setstate__(self, d): > if 'hair_color' not in d: > d['hair_color'] = 'brown' > self.__dict__.update(d) > print 'did this work?' > > Now when I unpickle the original pickled object sparky I would hope to > see 'did this work' and I would also hope that sparky would have updated > to have the attribute 'hair_color' but nothing of the sort happens. if > just unpickles sparky without updating the attributes as I was hoping. > > Thanks! > > Jeff > > > > > - > Never miss a thing. Make Yahoo your homepage. > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > -- View this message in context: http://www.nabble.com/setstate-trouble-when-unpickling-tp15082091p15121172.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor