Here's some sample code that demonstrates what I discovered:
Code: Select all
## Example of how to use Sense_Hat with numpy
from sense_hat import SenseHat
import numpy as np
sense = SenseHat()
sense.gamma = [i for i in range(32)]
sense.set_pixels([3*[i] for i in range(64)])
# Get the current pixel values in list form
pl = sense.get_pixels()
# Convert to an np.array
pa = np.array(pl)
# Resize the array into an 8 x 8 x 3 array
pa.resize(8,8,3)
# Manipulate the array to add three lines
pa[3:6,3,:] = [255, 0, 0]
pa[3:6,4,:] = [0, 255, 0]
pa[3:6,5,:] = [0, 0, 255]
# Send the new array to the sense hat
sense.set_pixels(pa.reshape(64,3))
# Which is simpler than the anticipated explicit conversion to a list:
# sense.set_pixels(pa.reshape(64,3).tolist())