如何用python批量生成变量/数组 How to define a batch of regular variables in python

【问题情境 Situation】

现在需要生成一系列数组变量形如a_1=[], a_2=[], a_3=[], ... , a_n=[],之所以不能用二维数组是因为这些list的长度在之后使用过程中并不相同,index也不一致,不方便计算

Assuming a series of variables like a_1=[], a_2=[], a_3=[], ... , a_n=[] need to be defined. Here it's not allowed to use 2-dimensional list or DataFrame, cause these lists have various length and index, a 2-d list won't work.

【解决方法 Solution】

这个方法以前我在matlab中屡试不爽,但在python中找了一会才找到这个函数,即,将字符串作为可执行代码执行的exec()。这是一个python内置函数,不需要导入其他toolkit,可以参考官方文件理解exec()

It took me a while to find this function in python, exec(), which executes strings as executable code. This is a python built-in function, you can refer to the official document to understand it. exec()

【示例 Exampl

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值