Overview

What is ulab

ulab (pronounced "micro lab") lets you perform number crunching tasks in CircuitPython more quickly, often around 10x as fast. This can be very handy when dealing with sensor data, as we'll see below.

Make sure you have CircuitPython 5.1.0 or newer, and any Adafruit CircuitPython board with an M4 or higher processor, including all SAMD51 and nRF boards.

ulab is modeled after numpy, but is not entirely compatible; so after the examples, we'll also provide you with some guidelines to help you move between numpy and ulab.

ulab is not available in Blinka, Adafruit's Single Board Computer layer for CircuitPython - for those boards we recommend using plain numpy since it's available! If your code needs to run on both CircuitPython and Blinka, you'll probably either need to use conditional code or forego the use of ulab altogether.

The ulab API

ulab makes things faster by operating on entire arrays of values in one operation.  For example, when you have two numbers a and b, a+b adds them together, returning a new number.  When you have two ulab arrays a and b, a+b adds the corresponding numbers in a to the corresponding numbers in b, returning a new array.  Want to double every number in an array?  That's a*2.  Compute its sine?  ulab.vector.sin(a).  It also has special versions of functions like sum that act on a whole array and return a single number.  Documentation for all functions in ulab are on readthedocs.

These examples only cover a portion of the functions available in ulab.  Major items we will not cover include:

  • Matrix functions in ulab.linalg, such as determinant, inverse, and eigenvectors of a matrix
  • Creating vectors with ulab.linspace, which is sort of like range() but for arrays
  • Statistical functions such as standard deviation in ulab.numerical
  • Functions for working with polynomials in ulab.polynomial
  • Slicing arrays with arr[lo:hi:step]

Parts

Adafruit CLUE - nRF52840 Express with Bluetooth LE

PRODUCT ID: 4500
Do you feel like you just don't have a CLUE? Well, we can help with that - get a CLUE here at Adafruit by picking up this sensor-packed development board. We wanted to build some...
$39.95
IN STOCK

Adafruit APDS9960 Proximity, Light, RGB, and Gesture Sensor

PRODUCT ID: 3595
This breakout is chock full o' sensors! Add basic gesture sensing, RGB color sensing, proximity sensing, or ambient light sensing to your project with the Adafruit...
$7.50
IN STOCK

Adafruit BMP280 I2C or SPI Barometric Pressure & Altitude Sensor

PRODUCT ID: 2651
Bosch has stepped up their game with their new BMP280 sensor, an environmental sensor with temperature, barometric pressure that is the next generation upgrade to the...
$9.95
IN STOCK

Flexible Silicone Neon-like Skinny NeoPixel LED Strip

PRODUCT ID: 4310
You love NeoPixels, and you love silicone diffusion? Peep this Flexible Silicone Neon-like Skinny NeoPixel LED Strip! OK it's a bit of a mouthful, but check...
$34.95
IN STOCK

USB cable - USB A to Micro-B

PRODUCT ID: 592
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Metro, Feather, Raspberry Pi or other dev-board or...
$2.95
IN STOCK
This guide was first published on Mar 06, 2020. It was last updated on Mar 06, 2020.
This page (Overview) was last updated on Jul 06, 2020.