Installing NumPy on the Pyboard

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
Iyassou
Posts: 34
Joined: Sun Jun 26, 2016 9:15 am

Installing NumPy on the Pyboard

Post by Iyassou » Thu Jun 30, 2016 11:52 am

Hello,

I want to install Numpy on my Pyboard so that I can use the handy numpy.linalg.det() function to find a matrix determinant. I was wondering if this is possible and if it is how is it done.

Thanks.

torwag
Posts: 216
Joined: Fri Dec 13, 2013 9:25 am

Re: Installing NumPy on the Pyboard

Post by torwag » Thu Jun 30, 2016 12:39 pm

There is no way to run numpy on the pyboard, since it is not ported to micropython and most likely never will be. Numpy is huge compared to micropython and it would make no sens to run it on a microcontroller.
What you might want to do, is to study the functions you need from numpy and try to implement them by yourself. But be aware, a uC and a PC are two different things. You need to estimate if a uC would be capable of performing the tasks you plan to do.
Furthermore, many algorithms have dedicated counterparts which work better on uC but are more limited in general.

Iyassou
Posts: 34
Joined: Sun Jun 26, 2016 9:15 am

Re: Installing NumPy on the Pyboard

Post by Iyassou » Thu Jun 30, 2016 5:45 pm

Thanks for the clarification concerning microcontrollers and numpy.

I ended up determining the matrix determinant expression by hand and ran it on my matrix (I'm handling a 4x4 matrix made up of 4 lists and no zeros in any of them) and it worked. It did take a while to find but at the end it's just a long addition so it's well in the microcontroller's capabilities.

Thanks again for the help.

User avatar
workless
Posts: 13
Joined: Sat Mar 24, 2018 7:03 pm
Location: Vancouver, BC

Re: Installing NumPy on the Pyboard

Post by workless » Sat Mar 24, 2018 7:58 pm

[quote=Iyassou post_id=11775 time=1467287560 user_id=1808]
Hello,

I want to install Numpy on my Pyboard so that I can use the handy numpy.linalg.det() function to find a matrix determinant. I was wondering if this is possible and if it is how is it done.

Thanks.
[/quote]

I knew that numpy would not exist for MicroPython but I was also a bit naive thinking there would be at least some basic "number-crunching" tools available. Even the built-in `array` object does not allow basic vectorization techniques such as element-wise multiplication.

Looks like @jlawson has written a fairly powerful module for 2D matrix operations - see this forum post: viewtopic.php?f=15&t=1169

It looks like a great piece of work but I think it is all written in Python (as opposed to machine code) so it is more of a convenience tool than a 'speed-up' option - e.g. for vectorization of large computations.

Surely someone will work on an implementation of numpy arrays and some basic functionality at some point?

E.g.:
- ndarray with dim, shape, size, dtype attributes and slicing capability (views)

And maybe the following commonly-used numpy array methods:
- mean, sum, max, argmax, min, argmin, dot, transpose, all, any, ravel/flatten, reshape, copy

(I wish I had the skills to do it but happy to assist if this is a project someone is working on).

Post Reply