'tuple' object is not callable解決方案
在按照書上的程式碼操作的時候,有些時候會遇到一些很奇怪的bug,標題就是一個這樣的bug。
操作例項的時候是用了shape函式
為了解決這個bug,查了很多資料,都沒有找到解決方案,最後不斷嘗試,並結合了一點經驗解決了。
解決之後發現問題也特別簡單
在python中,只有函式才是Callable(可Call的物件才是Callable)。但是tuple是一個數據型別,當然是不能Call(翻譯成:使喚,hhh可能會比較容易理解)
有bug的程式碼如下:
from numpy import *
a = array([[1, 3], [2, 4], [5, 6]])
print(a.shape(0 ))
要是能找到錯誤,就非常好了
其實錯誤很簡單
正確的程式碼如下
from numpy import *
a = array([[1, 3], [2, 4], [5, 6]])
print(a.shape[0])
其實這個bug應該很容易發現才對,但是,最近打了很多matlab的檔案()符號在MATLAB中就是[]的類似意思,所以找了很久。
分享給大家,供大家一起學習
覺得有點幫助就點個贊吧
最後,老套路,宣傳一波自己的公眾號!(求關注哇!)
本人中大一肥宅,歡迎大家關注,請掃下面的二維碼(〃’▽’〃)
如果覺得有幫助的話,可以掃碼,讚賞鼓勵一下!謝謝!
相關推薦
'tuple' object is not callable解決方案
在按照書上的程式碼操作的時候,有些時候會遇到一些很奇怪的bug,標題就是一個這樣的bug。 操作例項的時候是用了shape函式 為了解決這個bug,查了很多資料,都沒有找到解決方案,最後不斷嘗試,並結合了一點經驗解決了。 解決之後發現問題也特別簡單 在p
TypeError: 'bytes' object is not callable 解決方法
原始碼如下,定義的本地變數get_time和get_time()外部引入方法重名,呼叫get_time(),被當成了本地變數get_time= b'\d+ .\d+',變數不可被呼叫(函式才可呼叫)。 if __name__ == '__main__': get_time= b'\d+\
TypeError: ‘module’ object is not callable 解決
錯誤出現情況描述: 資料夾crossmodal中有兩個檔案 : correlation.py 裡面有correlation()方法 在test.py中 from crossmodal import correla
報錯:TypeError: 'NoneType' object is not callable問題解決
報錯:TypeError: ‘NoneType’ object is not callable問題解決方法 def dec(function): print("start...") function() print("end...") #修飾器 @dec def
appium 提示報錯“TypeError: 'unicode' object is not callable”的解決方式!
轉自:https://www.cnblogs.com/syw20170419/p/7018944.html 這裡提到的這個報錯,是小錯誤且容易經常會犯,有時需要特別注意使用。 目的要求結果:根據某個元素的id值獲取到對應id的text值,並且將獲取的text值與本身存在的text值做比較,檢
關於XGB.booster()報錯TypeError: 'str' object is not callable的解決方法
當使用XGB想得到特徵重要性時報錯,程式碼及報錯如下, model = XGBRegressor( learning_rate = 0.1, n_estimators = 300, max_depth = 7, min_child_weight =
解決:TypeError: 'list' object is not callable
如果list變數和list函式重名,會有什麼後果呢?我們可以參考如下程式碼: list = ['泡芙', '湯圓', '魚兒', '駱駝'] tup_1 = (1, 2, 3, 4, 5) tupToList = list(tup_1) print(tupToList)
TypeError: 'frozenset' object is not callable 的解決辦法
在ubuntu中通過pip安裝hashlib包時,會報TypeError: 'frozenset' object is not callable的錯誤 個人的解決辦法是通過https://files.pythonhosted.org/packages/74/bb/9003d081345e9f04
解決"學習python-flask教程,下載原始碼執行的時候出現:TypeError: 'bool' object is not callable 錯誤程式碼:"
我也跟著教程敲程式碼,Google老半天,結果在一篇俄國人的帖子中找的這個,https://plus.google.com/+MiguelGrinberg/posts/9o9idDfaYhK,尼瑪,Miguel Gr
TypeError:'dict' object is not callable
peer 錯誤 not typeerror obj dict 而不是 pytho pos TypeError:‘dict‘ object is not callable 出現這種錯誤有兩種可能: 1. 代碼裏重新定義了dict,比如 dict= {...},這時調用的
Python: TypeError: 'dict' object is not callable
color call error gpo -c typeerror python字典 type 問題 問題: TypeError: ‘dict‘ object is not callable 原因: dict()是python的一個內建函數,如果將dict自定義為一個p
python報錯'str' object is not callable
xxx nbsp 正在 bnt 沖突 報錯 nts bsp bject >>> x=1.235 >>> int(x) 1 >>> str="fsgavfdbafdbntsbgbt" >>>
python 報錯——Python TypeError: 'module' object is not callable 原因分析
erro 隱藏 import 分析 ide typeerror error: 自帶 In 原因分析:Python導入模塊的方法有兩種: import module 和 from module import 區別是前者所有導入的東西使用時需加上模塊名的限定,而後者則不需要
python3在pycharm中為什麽導入random模塊不能用? TypeError: 'module' object is not callable
新建 ron erro RR strong object bject 而且 content 新手學python求大神指導,也用sys導入了random.py的路徑,仍然不行。 剛剛排錯貌似找到了問題的原因。。。那是因為我在pycharm中新建的python文件名就是ran
AttributeError: module 'XXX' has no attribute 'xxx' && TypeError: 'module' object is not callable
AttributeError: module 'XXX' has no attribute 'xxx' && TypeError: 'module' object is not callable 最近在呼叫python的類的時候總是提示:module 'XXX' has no a
WEBGL_draw_buffers RENDER WARNING: texture bound to texture unit 0 is not..錯誤解決方案
今天在調整渲染系統中的一個MRT機制,結果不小心改錯了邏輯,執行報錯資訊:[.WebGL-00000000051B4190]RENDER WARNING: texture bound to texture unit 0 is not renderable. It maybe non-power-of
錯誤: TypeError: 'str' object is not callable,TypeError: 'int' object is not callable等
先說上面出現的原因: TypeError: 'str' object is not callable:就是str不可以被系統呼叫, TypeError: 'int' object is not callable:就是int不可以被系統呼叫 原因就是:你正在呼叫一個不能被呼叫的變數或物件,
TypeError: 'float' object is not callable
今天在做一道Python練習題時遇到的問題,記錄一下: 請輸入三個整數a,b,c,判斷能否以它們為三個邊長構成三角形。若能,輸出YES和麵積,否則輸出NO 剛開始寫的程式碼如下: a=int(input('請輸入一個整數:')) b=int(input('請輸入一個整數:')) c=in
【Python】'str' object is not callable/'int' object is not callable
‘str’ object is not callable/‘int’ object is not callable Python報錯TypeError: ‘str’ object is not callable 類似的還有 ‘int’ object is not callable s
Flask 中使用 JSON 響應頁面的 Ajax 請求報錯 TypeError: 'dict' object is not callable
在使用 Flask 的過程中,頁面向後臺發起 Ajax 請求,後臺處理完成後向頁面返回 JSON 資料時,會報出一個 TypeError: 'dict' object is not callable 的錯誤。該錯誤是因為直接將 {key:value} 形式的字典資料向頁面傳輸