在python中的while循环中创建固定大小的数组

2024-09-28 03:13:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在while循环中创建固定大小的数组。因为我不知道要创建多少个数组,所以我使用一个循环在while循环中启动它们。我面临的问题是,在数组声明中,我希望每个数组的名称以while循环的索引结尾,这样以后它将对我的计算有用。我不希望找到一个简单的出路,但是如果有人能给我指出正确的方向,那就太好了

我尝试使用arrayname+str(I)。这将返回错误“cannot assign to operator”。在

#parse through the Load vector sheet to load the values of the stress  vector into the dataframe
Loadvector = x2.parse('Load_vector')

Lvec_rows = len(Loadvector.index)
Lvec_cols = len(Loadvector.columns)

i = 0
while i < Lvec_cols:
    y_values + str(i) = np.zeros(Lvec_rows)
    i = i +1 

我希望数组名为arrayname1,arrayname2。。。待创建。在


Tags: theto声明lenparseload数组rows
1条回答
网友
1楼 · 发布于 2024-09-28 03:13:11

我认为这个标题有些误导。在

一种简单的方法是使用字典:

dict_of_array = {}
i = 0
while i < Lvec_cols:
    dict_of_array[y_values + str(i)] = np.zeros(Lvec_rows)
    i = i +1 

您可以通过dict_of_array[arrayname1]访问{}。在

如果要创建一批数组,请尝试:

^{pr2}$

相关问题 更多 >

    热门问题