Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2-d array using Python's array.array module?

array.array is a built-in type, looks like it will be much more efficient than list for some numerical tasks.

In numpy I could create a 2-d array easily, for example: a = numpy.asarray([[1,2][3,4]], dtype='int')

But I couldn't find how to create a 2-d array using array.array, can I?

like image 779
avocado Avatar asked Oct 31 '22 06:10

avocado


1 Answers

No, though you can do index math to emulate one (which is how they work behind the scenes anyway). array.array is useful for its storage and conversion capabilities but actual calculation on array contents is likely far more efficient using numpy. Of course you can also keep a list of arrays if you wish.

like image 199
Yann Vernier Avatar answered Nov 11 '22 06:11

Yann Vernier