I can successfully save & load small arrays using Numpy
. Now I am saving the below array using np.save('array.npy')
[0, 100, 0, 5, 10, 15, 20, 25, 30, 25, 20, 15, 10, 5, 0]
when I try to load using np.load('array.npy')
, it shows the below error:
raise ValueError("Cannot load file containing pickled data "
ValueError: Cannot load file containing pickled data when allow_pickle=False
If I try to solve it by adding allow_pickle=True
then it shows the below error:
raise IOError(
OSError: Failed to interpret file 'array.npy' as a pickle
Its really a difficult situation. Please advise! :(
The code I am referring to is below:
def recv():
import socket
import time
import numpy as np
TCP_IP = "0.0.0.0"
BUFFER_SIZE = 20 # Normally 1024, but we want fast response
# receiving CAN frame payload
TCP_PORT = 5003
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((TCP_IP,TCP_PORT))
s.listen(1)
conn,addr = s.accept()
while 1:
data1 = conn.recv(BUFFER_SIZE)
if not data1: break
datalist = list(data1)
print("CAN payload: %s" % datalist)
conn.send(data1) # echo
conn.close()
time.sleep(2)
# ------------------------------------------------------------
# assembling CAN frame
from can import Message
can_msg = Message(is_extended_id=bool(datalist[0]),arbitration_id=datalist[1],data=datalist[2:])
# printing all received payloads
print("CAN frame: ",can_msg)
print("Vehicle speed: ",datalist[2:])
# Saving all received payloads
np.save('array.npy',datalist[2:]) # save
def EPS_process():
# EPS process for Right turn, high speed
import numpy as np
print("Starting EPS process")
speed_array = np.load('array.npy') # load
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…