有没有办法告诉 numpy 在写入 python pickle 文件时保留非标准跨步?
>>> # Create an array with non-standard striding
>>> x = numpy.arange(2*3*4, dtype='uint8').reshape((2,3,4)).transpose(0,2,1)
>>> x.strides
(12, 1, 4)
>>> # The pickling process converts it to a c-contiguous array.
>>> # Often, this is a good thing, but for some applications, the
>>> # non-standard striding is intentional and important to preserve.
>>> pickled = cPickle.dumps(x, protocol=cPickle.HIGHEST_PROTOCOL)
>>> cPickle.loads(pickled).strides
(12, 3, 1)
>>> # This is indeed happening during serialization, not deserialization
>>> pickletools.dis(pickled)
...
151: S STRING '\x00\x04\x08\x01\x05\t\x02\x06\n\x03\x07\x0b\x0c\x10\x14\r\x11\x15\x0e\x12\x16\x0f\x13\x17'
...
注意: numpy 足够聪明,可以保留 c-contiguous 或 fortran-contiguous,但它不会保留酸洗和解酸过程中的所有非标准步幅模式。