5 ms·
I found myself nodding along with this until the bit about the array module. The array module is very well suited to doing real work. Maybe it seems arcane if y
by ghc 15y ago
I found myself nodding along with this until the bit about the array module. The array module is very well suited to doing real work. Maybe it seems arcane if you're coming from a web dev background, but given the space inefficiency of Python's lists, the array module is awfully useful in a lot of situations.
- apu 15y agoNot just space, but speed as well. I've often noted significant speedups in many operations by switching to array.array. In some cases, the speedups are comparable to or even slightly better than using numpy (which is much more heavy-weight).
- chimeracoder 15y agoOut of curiosity, what are you doing for which arrays are more suited than NumPy? I've been using NumPy for a while now, and I've literally never had a reason to use array.array where NumPy arrays have worked.
- apu 15y agoI find numpy too heavy weight for a lot of stuff and also not very good for communication/interchange with other programs. For a lot of my work, I often need to write data files to disk (for C programs to use) or mmap'ed files for concurrent access. In these situations, the fact that array.array offers precise data alignment rules and toString() and toFile() methods that are actually sane, I end up using it instead of numpy. Of course, if I do significant computations in my python program itself, I just use numpy.
- webexcess 15y agoGood point. I didn't address this adequately. The usual #python response to people using the array module was to instead consider NumPy (with its excellent arrays) or use normal lists and PyPy to make it fast.