range 、 xrange 、arange 区别:
今天看到了个arange(),在百度中是没有搜到答案,直接进google,当然有的是答案了@!
以后对这些貌似很像且有用的东西进行记录!
range()返回的是list;xrange 返回的是python中的xrange对象(一个生成器);arange返回的是一个numpy.narray对象,是numpy中的函数。
range(10)返回大小10,xrange返回xrange(10),占用内存很小,arange返回的是array([0,1,2,3,4,5,6……])大小10.
shallow copy and deep copy:
shallow copy:
>>> c = a.view()
>>> c is a
False
>>> c.base is a # c is a view of the data owned by a
True
>>> c.flags.owndata
False
>>>
>>> c.shape = 2,6 # a's shape doesn't change
>>> a.shape
(3, 4)
>>> c[0,4] = 1234 # a's data changes
>>> a
array([[ 0, 1, 2, 3],
[1234, 5, 6, 7],
[ 8, 9, 10, 11]])
deep copy:
>>> d = a.copy() # a new array object with new data is created
>>> d is a
False
>>> d.base is a # d doesn't share anything with a
False
>>> d[0,0] = 9999
>>> a
array([[ 0, 10, 10, 3],
[1234, 10, 10, 7],
[ 8, 10, 10, 11]])
matrix and array ,及其相应的乘法运算
numpy中有两种类型matrix and array,matrix的乘法运算和array的乘法运算在使用相同的运算符号可能会产生不同的结果!具体的说明请点击这里 论numpy中matrix和array的区别