def resampleToLengthN(v, n): # can't guarantee length = exactly n
if len(v.shape) == 1:
factor = int(len(v) / float(n))
if factor <= 1:
return v
# return downsampleBy(v, factor)
return signal.resample(v, n)
elif len(v.shape) == 2: # resample each row
rows = map(lambda row: resampleToLengthN(row.flatten(), n), v)
return np.vstack(rows)
else:
print("Error: can't resample tensor to length N!")
评论列表
文章目录