python - 'numpy.float64' 不能解释为整数
问题描述
我正在尝试使用 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)
解决方案
推荐阅读
- django - django admin 导出为 pdf
- java - Scanner.read() 不拾取分隔符的间歇性错误
- c# - 我对统一的 fov 可视化脚本有疑问
- python - paho-mqtt python包中的连接被拒绝错误
- ruby - Ruby:通过 TCP 套接字发送字符串
- php - 在信用卡支付中使用 Stripe
- swift - 为什么我不能执行鼠标左键单击?
- objective-c - 将(Swift WatchKit)目标添加到(Objective-C iOS)应用程序
- php - Laravel:用户登录后抛出 MethodNotAllowedHttpException
- python - 需要将pandas相关高亮表(cmap Matplotlib)保存为png图片