今天从github看到大神把吴恩达讲sparse autoencoder的MATLAB代码改写到python上,链接如下:https://github.com/jatinshah/ufldl_tutorial
遂直接copy,但是程序好像用的是python2.7写的,改了不少print语句,在运行的时候遇到些错误:
- TypeError: only integer scalar arrays can be converted to a scalar index
错误位置在 load_MNIST.py 中的 images = images.reshape(num_images, num_rows * num_cols) 。我琢磨这错误是说索引的type不对,后来发现前面代码中给索引赋值是用的numpy
num_images = np.fromfile(f, dtype=np.dtype('>i4'), count=1)
num_rows = np.fromfile(f, dtype=np.dtype('>i4'), count=1)
num_cols = np.fromfile(f, dtype=np.dtype('>i4'), count=1)
把索引强制改成int,程序没报错…这个大佬写的程序里面有很多这样的类型问题…
num_images = int( np.fromfile(f, dtype=np.dtype('>i4'), count=