[英]Appending values from one array to another array of unknown dimension
I have an array A of dimension (654 X 2).我有一个维度数组 A (654 X 2)。 Now within a loop, I have an 'if' statement.
现在在一个循环中,我有一个“if”语句。 If for a value of 'i', the condition is true, I need to append the values of 'i'th row of A into a separate array B. That means the dimension of B is not known to me beforehand.
如果对于“i”的值,条件为真,我需要将 A 的“第 i”行的值附加到单独的数组 B 中。这意味着我事先不知道 B 的维度。 So, how to initialize such array B in python.
那么,如何在python中初始化这样的数组B。 If this is not the procedure, suggest me alternative ways to execute the same.
如果这不是程序,请建议我执行相同的替代方法。
You could initialize B as empty array:您可以将 B 初始化为空数组:
B = []
Then when needs, just append it with the value:然后在需要时,只需将其附加值:
B.append( [x,y] )
you do not provide ANY code to start from, please read this to learn how to ask a question How to create a Minimal, Complete, and Verifiable example您没有提供任何代码作为起点,请阅读本文以了解如何提出问题如何创建最小、完整和可验证的示例
from the almost 0 information that you've provided从您提供的几乎 0 条信息中
you should try doing something like this:你应该尝试做这样的事情:
B = []
for i in range(n):
if i % 2 == 0: # example of condition
B += [ A[i] ]
print(B)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.