前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python: zip 与 * 探究

python: zip 与 * 探究

作者头像
JNingWei
发布2018-09-28 15:51:29
3240
发布2018-09-28 15:51:29
举报
文章被收录于专栏:JNing的专栏

结论

  因为之前对python中的 zip * ,搞得不是很清楚,这次做项目时又遇到这个问题,所以上网查阅,并经过自己编写代码进行实验,得出以下结论:

作用域

zip()

zip(* )

简述

将list合并打包

将list进行unpack

在rank上的变化

插入axis=1,其余不变

将axis=0和axis=1对换,其余不变

在type上的变化

ndarray –> list

ndarray –> list

附上自己写的实验源码

代码语言:javascript
复制
import numpy as np

a = np.zeros(shape=[3, 5, 6], dtype=np.int)

print np.shape(a), ':', type(a)
for b in a:
    print np.shape(b)
print

print np.shape(zip(a)), ':', type(zip(a))
for b in zip(a):
    print np.shape(b)
print

print np.shape(zip(zip(a))), ':', type(zip(zip(a)))
for b in zip(zip(a)):
    print np.shape(b)
print

print np.shape(zip(*a)), ':', type(zip(*a))
for b in zip(*a):
    print np.shape(b)
代码语言:javascript
复制
(3, 5, 6) : <type 'numpy.ndarray'>
(5, 6)
(5, 6)
(5, 6)

(3, 1, 5, 6) : <type 'list'>
(1, 5, 6)
(1, 5, 6)
(1, 5, 6)

(3, 1, 1, 5, 6) : <type 'list'>
(1, 1, 5, 6)
(1, 1, 5, 6)
(1, 1, 5, 6)

(5, 3, 6) : <type 'list'>
(3, 6)
(3, 6)
(3, 6)
(3, 6)
(3, 6)

Process finished with exit code 0


本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017年08月29日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 结论
  • 附上自己写的实验源码
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档