我正在尝试在python中编写一些用于数据分段的代码,这是我的代码 它由两个功能组成。我使用了python 3.5
def windowz(data, size):
start = 0
while start < len(data):
yield start, start + size
start += (size / 2)
def segment_dap(x_train,y_train,window_size):
segments = np.zeros(((len(x_train)//(window_size//2))-1,window_size,9))
labels = np.zeros(((len(y_train)//(window_size//2))-1))
i_segment = 0
i_label = 0
for (start,end) in windowz(x_train,window_size):
if(len(x_train[start:end]) == window_size):
m = stats.mode(y_train[start:end])
segments[i_segment] = x_train[start:end]
labels[i_label] = m[0]
i_label+=1
i_segment+=1
return segments, labels
input_width = 23
if dataset =="dap":
print ("dap seg")
input_width = 25
print ("segmenting signal...")
train_x, train_y = segment_dap(x_train,y_train,input_width)
test_x, test_y = segment_dap(x_test,y_test,input_width)
print ("signal segmented.")
但是这段代码给了我以下警告
Warning (from warnings module):
File "C:\Users\hp\Downloads\Deep-Learning-for-Human-Activity-Recognition-master\ModelCreation\RNN\FFLSTM\fflstm.py", line 37
if(len(x_train[start:end]) == window_size):
VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
Warning (from warnings module):
File "C:\Users\hp\Downloads\Deep-Learning-for-Human-Activity-Recognition-master\ModelCreation\RNN\FFLSTM\fflstm.py", line 38
m = stats.mode(y_train[start:end])
VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
Warning (from warnings module):
File "C:\Users\hp\Downloads\Deep-Learning-for-Human-Activity-Recognition-master\ModelCreation\RNN\FFLSTM\fflstm.py", line 39
segments[i_segment] = x_train[start:end]
VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
答案 0 :(得分:2)
(size / 2)
in:
def windowz(data, size):
start = 0
while start < len(data):
yield start, start + size
start += (size / 2)
会给你一个浮动。你可以强制它是一个整数:
(size // 2)