简体   繁体   English

如何通过从现有的 arrays 数组追加来创建和排列 arrays

[英]How to create and array of arrays by appending from an existing array of arrays

I want to take an array of int arrays and either turn it into or make an array of sting arrays.我想获取一组 int arrays 并将其转换为或制作一组 sting arrays。 I know how to turn the ints into strings but what im struggling with is as follows: when I append from the original array of arrays, it makes the new array ONE array, with ALL of the contents of the array of arrays.我知道如何将整数转换为字符串,但我正在努力解决的问题如下:当我从 arrays 的原始数组中获得 append 时,它使新数组 ONE 数组包含 ZA3CBC3F9D672F21D9CZE 数组的所有内容。 I would like it to be an array of arrays as well, not one array.我也希望它是 arrays 的数组,而不是一个数组。 Note: xAxisValuesContainer and yAxisValuesContainer are both array of arrays where each sub array is of type number/int.注意:xAxisValuesContainer 和 yAxisValuesContainer 都是 arrays 的数组,其中每个子数组的类型为 number/int。

strXaxis = []
for i in range(len(xAxisValuesContainer)):
  for j in range(len(xAxisValuesContainer[i])):
    strXaxis.append(str(xAxisValuesContainer[i][j]))

strYaxis = []
for i in range(len(yAxisValuesContainer)):
  for j in range(len(yAxisValuesContainer[i])):
    strYaxis.append(str(yAxisValuesContainer[i][j]))

First of all, these are lists, not arrays.首先,这些是列表,而不是 arrays。

You need to make a nested list in the outer loop.您需要在外循环中创建一个嵌套列表。

You can do all of this with nested list comprehensions:您可以使用嵌套列表推导来完成所有这些操作:

strXaxis = [[str(value) for value in row] for row in xAxisValuesContainer]]
strXaxis = [[str(value) for value in row] for row in yAxisValuesContainer]]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM