在python中将list分段并保存为array类型的方法
作者:Pywin 时间:2023-11-15 10:18:00
如下所示:
list=[1,2,3,4,5,6,7,8,9,0,11,0,13,14,15,16,17,18,19,20]
#把list分为长度为5的4段
for j in range(0,len(list),5):
matrix.append(list[j:j+5])
matrix=np.array(matrix)#转array型
print matrix[0]#输出第一段
结果:
[[ 1 2 3 4 0]
[ 6 7 8 0 0]
[11 0 13 14 15]
[16 0 18 19 20]]
来源:https://blog.csdn.net/qq_36076233/article/details/77838645
标签:python,list,分段,保存,array
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
解决vue中less的使用问题
2024-05-03 15:11:05
![](https://img.aspxhome.com/file/2023/7/130197_0s.png)
Web内容写作:得到更好稿件的头15条规则[译]
2011-06-09 14:38:00
Mootools 1.2教程(5)——事件处理
2008-11-19 16:33:00
php字符串使用详细了解
2023-06-06 04:19:07
Pandas数据处理加速技巧汇总
2023-08-12 19:02:36
![](https://img.aspxhome.com/file/2023/8/105268_0s.png)
使用typescript快速开发一个cli的实现示例
2023-08-30 07:25:25
![](https://img.aspxhome.com/file/2023/6/56016_0s.png)
TensorFlow的reshape操作 tf.reshape的实现
2022-03-31 01:14:13
Python中的异常处理try/except/finally/raise用法分析
2023-12-11 21:37:41
Python线性表种的单链表详解
2022-03-02 07:36:58
![](https://img.aspxhome.com/file/2023/4/90694_0s.png)
Golang Gin局部和全局中间件使用详解
2023-07-10 03:03:00
![](https://img.aspxhome.com/file/2023/7/86297_0s.jpg)
JS语法检查插件 jsLint for Vim
2010-11-15 21:31:00
![](https://img.aspxhome.com/file/UploadPic/201011/15/01-50s.jpg)
仿QQ和MSN消息提示的效果代码
2010-03-16 12:17:00
Python实现批量自动整理文件
2023-05-10 21:58:12
![](https://img.aspxhome.com/file/2023/7/110577_0s.png)
python开发利器之ulipad的使用实践
2021-07-25 00:55:17
![](https://img.aspxhome.com/file/2023/8/90618_0s.jpg)
PHP实现的DES加密解密类定义与用法示例
2023-07-17 08:55:54
如何利用JS将手机号中间四位变成*号
2024-02-23 20:07:51
自定义404错误页面实现自动跳转
2007-12-10 18:25:00
Jmeter调用Python脚本实现参数互相传递的实现
2023-10-27 23:45:01
![](https://img.aspxhome.com/file/2023/1/117941_0s.png)
pandas和spark dataframe互相转换实例详解
2022-12-12 20:26:38
CSS控制字体效果的思考
2011-06-14 09:44:02
![](https://img.aspxhome.com/file/UploadPic/20072/20072311315168s.gif)