python for循环中的i与前面定义的数组怎么定义_在for循环中创建多个数组(Python)...

我现在对Numpy数组有问题。如果这个问题已经被问到其他地方,我很抱歉,但我觉得我已经到处找过了。

我最初的问题是试图创建一个数组,并用多组不同大小的站点数据填充它。因为我不能用大小不同的数据集填充同一个数组,所以我决定需要为每个station数据集创建一个新数组,方法是在for循环中定义用于遍历每个station数据集的数组。这样做的问题是,在循环过程中,每个数据集将覆盖以前的数据集,只返回for循环的最终实例。

然后,我尝试使用+和join操作连接每个数组的一个新标题,但在定义数组时发现这是非法的。这是程序的实例,其中每个数据数组都覆盖上一个数组。注意,并不是所有的代码都包含在内,这是定义的一部分。for k in range(len(stat_id)):

## NOTE - more code precedes this final portion of the for loop, but was

## not included as it is unrelated to the issue at hand.

# Bring all the data into one big array.

metar_dat = np.zeros((len(stat_id),len(temp),7), dtype='object')

for i in range(len(temp)):

metar_dat[k,i] = np.dstack((stat_id[k], yr[i], month[i], day[i], time[i], temp[i], dwp[i]))

#print np.shape(metar_dat[k])

#print metar_dat[k]

#print np.shape(metar_dat) # Confirm success with shape read.

return metar_dat

在运行并打印此定义中的数组时,我得到以下结果(两个空数组和一个最终填充数组):[[[0 0 0 ..., 0 0 0]

[0 0 0 ..., 0 0 0]

[0 0 0 ..., 0 0 0]

...,

[0 0 0 ..., 0 0 0]

[0 0 0 ..., 0 0 0]

[0 0 0 ..., 0 0 0]]

[[0 0 0 ..., 0 0 0]

[0 0 0 ..., 0 0 0]

[0 0 0 ..., 0 0 0]

...,

[0 0 0 ..., 0 0 0]

[0 0 0 ..., 0 0 0]

[0 0 0 ..., 0 0 0]]

[[\TZR 2015 7 ..., 2342 58 48]

[\TZR 2015 7 ..., 2300 59 47]

[\TZR 2015 7 ..., 2200 60 48]

...,

[\TZR 2015 7 ..., 0042 56 56]

[\TZR 2015 7 ..., 0022 56 56]

[\TZR 2015 7 ..., 0000 56 56]]]

我的问题是:

如何为每组站数据创建一个数组,以便不覆盖任何以前的数据?

或者

如何创建包含不同行数的数据集的单个数组?

我对Python还不熟悉(也不太熟悉这里的帖子),任何想法都会非常感谢。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值