程序问题

lu的raspi 35cm2022-11-10511 次点击
有没有大佬帮忙看一下程序问题
```
from __future__ import print_function
from sys import stdout
from time import sleep
from matplotlib import pyplot as plt
from matplotlib.pyplot import MultipleLocator
from tensorflow.keras.models import load_model
import threading
import numpy as np
import pandas as pd
import datetime
from sklearn.preprocessing import MinMaxScaler
modelfilepath='model.best.hdf5'

CURSOR_BACK_2 = '\x1b[2D'
ERASE_TO_END_OF_LINE = '\x1b[0K'
arraydata=[[0 for i in range(6000)] for h in range(10)]
# arraydata=np.empty([10,6000])
def writefile(arrayatt, fnat):
print("write file ", datetime.datetime.now())
np.savetxt(fnat, arrayatt.T, fmt="%1.2f", delimiter=" ")
print("\033[0;31m","finish write ", datetime.datetime.now(),"\033[0m")

#====Analyse and writefile and Alarm=======================================================
def analyse(array,fnat):
file1 = "1-"+fnat
data=np.array(array)
data = data.reshape((10,6000))
testmodel=load_model(modelfilepath)
correctCount=0
for i in range(10):
data=data[i]
data=MinMaxScaler(feature_range=(0,1)).fit_transform(data)
data=data.reshape((1,6000,1))
print(data)
# classifierResult = np.argmax(testmodel.predict(data,batch_size=(1)),axis=1)
# print("树莓派得到的辨识结果是: %d, 实际值是: %d" % (classifierResult, 1))
# if (classifierResult == 1):
# correctCount += 1.0
# if correctCount>=2:
# print('电路出现故障')
# t1 = threading.Thread(target=writefile, args=(data, file1,)) #调用写文件进程
# t1.start()

print("analyse file ", datetime.datetime.now())
def main():
try:
while True:
fna = str(datetime.datetime.now()) + ".txt"
kgdy=np.loadtxt('F:/dataone/sanzhouqi/kgdy/arckgdygy.csv',delimiter=',')[0:10,1:6001]
# kgdy = pd.read_csv('F:/dataone/sanzhouqi/kgdy/zckgdygy.csv', header=None)
for i in range(10):
arraydata[i]=kgdy[i]

arraydatat = arraydata

t2 = threading.Thread(target=analyse, args=(arraydatat, fna, ))
t2.start()
except KeyboardInterrupt:
print(CURSOR_BACK_2, ERASE_TO_END_OF_LINE, '\n')
print('Stopping')

if __name__ == '__main__':
main()
错误:
ValueError: Expected 2D array, got 1D array instead:
array=[0.71948312 0.71911951 0.71911951 ... 0.71956003 0.71956003 0.71938522].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
```
收藏 ♥ 感谢
Spoony 小组长 2022-11-10 
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

这句话翻译一下就是问他所在了
ezgamer 2022-11-11 
你用的是1d-array,需要一个二维数组,看看哪行的报错

登录注册 后可回复。



GitHub