我有一个包含两列的文本文件,我需要选择其中一列作为数组,该数组包含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,)
有任何帮助吗?
2nd_columns_array
,不再需要remain_points
和cut_points
这两个变量。请确保按照我在片段中所做的方式进行操作。 - machnic