上篇文章中的reshape(-1,2),有的时候不明白为什么会有参数-1,可以通过查找文档中的reshape()去理解这个问题 根据Numpy文档(https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html#numpy-reshape)的解释: newshape : int or tuple of ints The new shape should be compatible with the original…
>>> a = np.array([[1,2,3], [4,5,6]]) >>> np.reshape(a, (3,-1)) # the unspecified value is inferred to be 2 array([[1, 2], [3, 4], [5, 6]]) -1表示我懒得计算该填什么数字,由python通过a和其他的值3推测出来. # 下面是两张2*3大小的照片(不知道有几张照片用-1代替),如何把所有二维照片给摊平成一维 >>>…