好多坑踩过要是没记下来就容易又踩到。
numpy里带的array比Python自带的list好用得多,于是就需要由list向array转换
l = [1, 2, 3, 4]
l = np.array(l)
l.reshape(2, -1)
print l
# (4,)
为啥都reshape了,结构还是没变呢?
因为reshape方法是创建指定形状的新数组,而原数组的形状保持不变:
d = l.reshape(2, -1)
print a
# (2, 2)
但d和l实际上是共享存储空间的,修改其中任意一个数组的元素都会同时修改另外一个数组的内容。