[英]How can i store values from one array to another array?
I have two text files, which contain Bangla language plain text.我有两个文本文件,其中包含孟加拉语纯文本。 I read the two files and store each file's text line by line in two arrays.
我读取了这两个文件并将每个文件的文本逐行存储在两个数组中。 Now I am trying to store one array value into another array but I found an error.
现在我试图将一个数组值存储到另一个数组中,但我发现了一个错误。 Code is bellow with the error message.
代码与错误消息如下。
f = open("doc1.txt", encoding = 'utf-8')
a1 = f.read()
f = open("doc2.txt", encoding = 'utf-8')
a2 = f.read()
sentence1 = a1.split("।")
sentence2 = a2.split("।")
np_sent1 = np.array(sentence1)
np_sent2 = np.array(sentence2)
len_np_sent1 = len(np_sent1)
len_np_sent2 = len(np_sent2)
rint(np_sent1.shape)
for x in range(len_np_sent2):
len_np_sent1 = len_np_sent1 + 1;
np_sent1[len_np_sent1] = np_sent2[x]
print(np_sent1,len(np_sent1))
Error message:错误信息:
IndexError: index 11 is out of bounds for axis 0 with size 10
15 np_sent1[len_np_sent1] = np_sent2[x]
You can use either np.append
or np.concatenate
.您可以使用
np.append
或np.concatenate
。
np.append
uses np.concatenate
internally. np.append
np.concatenate
内部使用np.concatenate
。
Change改变
for x in range(len_np_sent2):
len_np_sent1 = len_np_sent1 + 1;
np_sent1[len_np_sent1] = np_sent2[x]
To到
np_sent1 = np.append(np_sent1, np_sent2)
OR或者
np_sent1 = np.concatenate((np_sent1, np_sent2))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.