亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

數組在python中不可調用“'numpy.ndarray'對象不可調用”

數組在python中不可調用“'numpy.ndarray'對象不可調用”

素胚勾勒不出你 2021-09-11 14:53:59
我正在研究神經網絡,當我嘗試對兩個 numpy.ndarray 進行混洗時,出現此錯誤。我嘗試重新檢查 shuffle 函數格式,但找不到任何錯誤。請幫忙train_images,train_labels = shuffle(train_images,train_labels)TypeError                                 Traceback (most recent call last)<ipython-input-8-b3f4173331ac> in <module> 18     print("Training the Network") 19     for i in range(epoch): 20     --> train_images,train_labels = shuffle(train_images,train_labels) 21         for offset in range (0,no_eg,batch_size): 22             end = offset+batch_size/usr/lib/python3.5/random.py in shuffle(self, x, random)275             for i in reversed(range(1, len(x))):276                 # pick an element in x[:i+1] with which to exchange x[i]277            -->  j = _int(random() * (i+1))278                 x[i], x[j] = x[j], x[i]279 TypeError: 'numpy.ndarray' object is not callabl
查看完整描述

2 回答

?
慕村225694

TA貢獻1880條經驗 獲得超4個贊

看看random.shuffle(x[, random])的文檔

可選參數 random 是一個 0 參數函數,返回 [0.0, 1.0) 中的隨機浮點數;默認情況下,這是函數 random()

在您的情況下,您通過 train_labels,根據錯誤消息,它是 numpy.ndarray,而不是函數


查看完整回答
反對 回復 2021-09-11
?
千萬里不及你

TA貢獻1784條經驗 獲得超9個贊

shuffle您可能想要使用兩個已命名的函數,但它們都沒有按您期望的方式工作。


random.shuffle(x, random=None)x使用函數洗牌列表random。


numpy.random.shuffle(x)打亂 NumPy 數組x。


這兩個函數一次只能打亂一個數組,但是你想打亂兩個數組,而且你想一致地打亂它們??紤]構建一個熊貓系列,對系列進行混洗(“采樣”),然后再次將其拆分為值和標簽:


import pandas as pd

series = pd.Series(train_images, index=train_labels)

shuffled = series.sample(series.size)

train_images_shuffled = shuffled.values

train_labels_shuffled = shuffled.index


查看完整回答
反對 回復 2021-09-11
  • 2 回答
  • 0 關注
  • 343 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號