'numpy.float64'无法解释为整数

时间:2019-07-12 12:03:24

标签: python numpy matrix light adafruit

我正在尝试使用NumPy矩阵为dotstar LED拾取颜色和亮度,但是当即将要拾取矩阵元素时,我收到numpy.float64错误,说不能将其解释为整数。我不知道numpy.float64的来源或为什么在我的代码中。

#5 light pulse using matrices to pick colours and brightness:

import time
import random
import board
import adafruit_dotstar as dotstar

#numpy introduces matrices:
import numpy as np

dots = dotstar.DotStar(board.D6, board.D5, 15, brightness=1)

#finds the number of dots on the strip:
n_dots = int(len(dots))  

#matrix of colours and their brightness:

dots_matrix = np.array([[(255,0,0,0.1),(255,0,0,0.5),(255,0,0,1)],
                        [(255,50,0,0.1),(255,50,0,0.5), (255,50,0,1)],
                        [(0,255,0,0.1), (0,255,0,0.5), (0,255,0,1)]])

#matrix element picking function:

def colour_choose(dot_number):
    if dot_number < 5:
        return dots_matrix[0][2]
    elif 4 < dot_number < 10:
        return dots_matrix[1][2]
    elif 9 < dot_number < 18:
        return dots_matrix[2][2]

def dim_colour_choose(dot_number):
    if dot_number < 5:
        return dots_matrix[0][1]
    elif 4 < dot_number < 10:
        return dots_matrix[1][1]
    elif 9 < dot_number < 18:
        return dots_matrix[2][1]

def dimmest_colour_choose(dot_number):
    if dot_number < 5:
        return dots_matrix[0][0]
    elif 4 < dot_number < 10:
        return dots_matrix[1][0]
    elif 9 < dot_number < 18:
        return dots_matrix[2][0]






while True:
    for x in range(3,18):
        dots[(x-2)%n_dots]=dimmest_colour_choose((x-2)%n_dots)
        dots[(x-1)%n_dots]=dim_colour_choose((x-1)%n_dots)
        dots[(x)%n_dots]=colour_choose((x)%n_dots)
        dots[(x+1)%n_dots]=dim_colour_choose((x+1)%n_dots)
        dots[(x+2)%n_dots]=dimmest_colour_choose((x+2)%n_dots)
        dots[x-3]=off
        time.sleep(0)

0 个答案:

没有答案