Skip to main content

Posts about numpy

Recurse Center, 2014-07-14

  • Monday morning checkins for our group had only two people. That was strange! Very strange!

Work on cinspect

  • I wrote up a README since David (an alum at Hacker School) showed interest in the project. But, he probably isn't that interested anymore since the code base is Python2.x only.
  • I got rid of assumptions that method names would start with the module name or the type name, and actually look up references to the names in the definitions of types or objects.
  • I also improved the test-suite to actually download sources of CPython and index them. They take very very long!!
  • I tried to get it working with Numpy, but getting all the headers to include wasn't as easy as I assumed it would be!

Augmented assignment in Python

If you are new to Python, you should probably stop reading here. But, if you have used Python and numpy, then read on. Before, that try these bits of code.

import numpy
a = numpy.array([1,2])
a = a + 0.5j
print a

The "same thing", in a slightly different way.

import numpy
a = numpy.array([1,2])
a += 0.5j
print a

Both the code blocks, look really the same, until you look carefully. Under normal circumstances a = a + b and a += b behave exactly similarly, and we really don't need to bother about the differences between them.

But, +=, which is an augmented assignment operator, actually tries to perform the operation in-place, unlike the other statement where + actually returns a new object which is again being referenced by the name a.

But, when dealing with numpy arrays, this will lead to trouble. When assigning to an array, it's dtype is not changed and hence the trouble.

The right way to use the augmented assignment operator, would be:

import numpy
a = numpy.array([1,2], dtype=complex)
a += 0.5j
print a

The same thing is explained in this thread. Also, Thanks to Bhanukiran for asking me this.

numpy, pacman and me

I'm now officially a part of the Arch Linux community! Arch Linux is a lightweight and flexible Linux® distribution that tries to Keep It Simple.

I have started using arch from less than a week or so. It took me a while, not too long, to realize the beauty of this distro. I was trying to tweak the settings of my org-mode's remember (on Karmic), trying to make it work the way I liked it. After breaking my head with .emacs and lisp for a while, I realized the version of my org-mode was way different from the version of the docs, I was reading. It didn't take long to figure out, which version of org-mode to get. As a matter of curiosity, I checked AUR for the version, and true to Arch's reputation it was bleeding edge! I was still using Karmic, since I hadn't got my Arch installation working the way I like it, yet. Out of laziness. sudo reboot; to hell with laziness!

I was setting up things I regularly use, tweaking my way around. After a day or so, I find python-numpy is out of date. And to top it, an orphaned package! I didn't feel one bit good about this. After some futile attempts to suppress my discomfort, I sat down to work.

After an afternoon of effort, I created my first PKGBUILD. :) I now have python-numpy installed using pacman! Pleasure to join the Arch User Community! Also, thanks to lifeeth and Lynus Vaz, for the sparks.

PS: I'm using Arch with Openbox. It's neat! PPS: org-mode is really awesome! It's a world in itself. life in plain text, truly!]