gpt4 book ai didi

python - 错误号 32 : Broken pipe

转载 作者:太空宇宙 更新时间:2023-11-04 10:51:02 25 4
gpt4 key购买 nike

下面是我收到 Broken Pipe 错误的代码。对于小数据集,我没有收到此错误。只有当数据集很大时才会出现这种情况。我也无法通过异常来处理它。

## reading the data from CSV file
import csv
csv_file='Two_Patterns_TRAIN.csv'
data=[]
with open (csv_file,'rb') as csv_file:
csvreader=csv.reader(csv_file, delimiter=';',quotechar='|')
## fetch the rows one by one
for row in csvreader:
## split the rows in columns
columns=row[0].split(',')
myrow=[]
for col in range(len(columns)):
## fetch the columns one by one and append it to the according row
myrow.append(float(columns[col]))
data.append(myrow)


def dtw(seqA, seqB, d = lambda x,y: abs(x-y)):
# create the cost matrix
numRows, numCols = len(seqA), len(seqB)
cost = [[0 for _ in range(numCols)] for _ in range(numRows)]

# initialize the first row and column
cost[0][0] = d(seqA[0], seqB[0])
for i in xrange(1, numRows):
cost[i][0] = cost[i-1][0] + d(seqA[i], seqB[0])

for j in xrange(1, numCols):
cost[0][j] = cost[0][j-1] + d(seqA[0], seqB[j])

# fill in the rest of the matrix
for i in xrange(1, numRows):
for j in xrange(1, numCols):
choices = cost[i-1][j], cost[i][j-1], cost[i-1][j-1]
cost[i][j] = min(choices) + d(seqA[i], seqB[j])

return cost[-1][-1]

def knn(mat,k):
## fetch number of rows and columns of the matrix
nrow=len(mat)
if nrow<k:
print "K can not be larger than n-1"
return
neigh=[[0]*k for i in range(nrow)]
for i in range(nrow):
dist=[[0]*2 for count in range(nrow)]
for j in range(nrow):
dist[j][0]=j+1
dist[j][1]=dtw(mat[i],mat[j])
dist = sorted(dist, key=lambda a_entry: a_entry[1])
neigh[i]=[row[0] for row in dist][1:k+1]
# print neigh
return neigh

a=data[:500]
b=data[501:]
try:
c=knn(a,5)
except IOError, e:
print e

下面是我得到的错误

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/monitor.py", line 588, in run
already_pickled=True)
File "/usr/lib/python2.7/dist-packages/spyderlib/utils/bsdsocket.py", line 24, in write_packet
sock.send(struct.pack("l", len(sent_data)) + sent_data)
error: [Errno 32] Broken pipe

最佳答案

看起来您正在使用 Spyder IDE。

根据 Issue 1474,这似乎是 Spyder 2.1.10 中的一个已知问题。 (Issue 1106)。

Spyder 2.2 似乎提供了修复。

关于python - 错误号 32 : Broken pipe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31035010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com