码迷,mamicode.com
首页 > 编程语言 > 详细

Python list 遇到的问题

时间:2018-11-10 21:09:17      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:nump   相同   matrix   nbsp   div   基础   操作   视图   ===   

1.list“+” 运算

<list += > diff. <ndarray +=>

list1 += list2是追加,而不是加法运算

list1 = [0,0,0]
list2 = [1,1,1]
list1 += list2
list1
[0, 0, 0, 1, 1, 1]

 

ndarray1 += ndarray2是加法运算,要求维度相同

nda1 = np.arange(3)
nda2 = np.arange(3)
nda1 += nda2
nda1
array([0, 2, 4])

 

2.关于list的引用(具体来说是元素为引用的list;ndarray也是如此)

Matrix1 = [[0,0,0],[1,1,1]]
list1 = Matrix1[0]
list2 = Matrix1[1]
list1 += list2
Matrix1
[[0, 0, 0, 1, 1, 1], [1, 1, 1]]

 

======================================

python居然这么多基础操作都是给引用而不是深拷贝 - -

Numpy的视图与拷贝

赋值操作(=)与切片都是浅拷贝…

 

Python list 遇到的问题

标签:nump   相同   matrix   nbsp   div   基础   操作   视图   ===   

原文地址:https://www.cnblogs.com/peanutk/p/9940438.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!