排列大小为k的Numpy数组

问题描述 投票:0回答:1

我正在尝试从MNIST数据库中提取大小为K的随机样本,并使用Jupyter笔记本中的子图显示它们。我的代码如下:

import numpy as np     
import matplotlib.pyplot as plt      
np.random.seed(0)

def draw_digits(X: np.ndarray, Y: np.ndarray, K: int = 20):
N,D=X.shape
order=np.arrange(K)
permute(order)
figure()
for i in range(64):
    if i>=len(order):
        break
    subplot(8,8,i+1)
    imshow(-X[order[i],:].reshape(28,28).T, cmap=cm.gist_gray)
    text(0,6,str(Y[order[i]]),color='blue')
    axis('off') 

我尝试了各种导入numpy的方式,包括

import numpy as np
from numpy import *

似乎都没有用。我不断得到:

module 'numpy' has no attribute 'arrange'

感谢您的任何帮助。

python numpy jupyter-notebook mnist
1个回答
0
投票
您应该尝试使用np.arange()而不是np.arrange()
© www.soinside.com 2019 - 2024. All rights reserved.