简体   繁体   English

在 Python 中创建一个二维数组

[英]Create a 2D array in Python

I'm trying to create a 2D array that ranges for 1 to 70 years and 1-12 for each year.我正在尝试创建一个范围为 1 到 70 年和每年 1-12 年的二维数组。 For example using some kind of for loop to get this below:例如,使用某种 for 循环来获得以下信息:

EDTI: index = (1,1),(1,2),(1,3)....(1,12), (2,1)...(2,12),(3,1)...(3,12).....(70,12) EDTI:索引 = (1,1),(1,2),(1,3)....(1,12), (2,1)...(2,12),(3,1) ...(3,12).....(70,12)

and then create a multi-index dataframe.然后创建一个多索引 dataframe。

I want the result of the code below to be in array format that I can set as multi-index.我希望下面代码的结果是可以设置为多索引的数组格式。

for j in range(1,71):
    for i in range(1,13)
        print(j,i)

apologies for the bad/vague original question为糟糕/模糊的原始问题道歉

[[i for i in range(1, 13)] for j in range(1, 71)]

This code uses list comprehension .此代码使用列表理解

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

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