【发布时间】:2019-01-07 19:39:23
【问题描述】:
我有一个包含 2 列的文本文件,我需要选择其中的一列作为数组 其中包含 200000 并从该数组中剪切 N 个元素并将它们从后向前移动。
我使用了以下代码:
import numpy as np
import glob
files = glob.glob("input/*.txt")
for file in files:
data_file = np.loadtxt(file)
2nd_columns = data_file [:,1]
2nd_columns_array = np.array(2nd_columns)
cut = 62859 # number of elements to cut
remain_points = 2nd_columns_array[:cut]
cut_points = 2nd_columns_array[cut:]
new_array = cut_points + remain_points
它不起作用并给了我以下错误:
ValueError: operands could not be broadcast together with shapes (137141,) (62859,)
有什么帮助吗??
【问题讨论】:
标签: arrays python-3.x slice python-import