Python:Python3錯誤提示TypeError: slice indices must be integers or None or have an __index__ method解決辦法
Python:Python3錯誤提示TypeError: slice indices must be integers or None or have an __index__ method解決辦法
在執行Python 3指令碼時,報錯:TypeError: slice indices must be integers or None or have an __index__ method
,報錯位置:
# Now add left and right halves of images in each level
ls_image = []
for la, lb in zip(lp_image1, lp_image2):
rows, cols, dpt = la.shape
ls = np.hstack((la[:, 0:cols / 2], lb[:, cols / 2:]))
ls_image.append(ls)
出錯程式碼行為:
ls = np.hstack((la[:, 0:cols / 2], lb[:, cols / 2:]))
問題原因:
In Python 3.x, 5 / 2
will return 2.5
and 5 // 2
will return 2
. The former is floating point division, and the latter is floor division, sometimes also called integer division.
In Python 2.2 or later in the 2.x line, there is no difference for integers unless you perform a from __future__ import division
, which causes Python 2.x to adopt the 3.x behavior.
Regardless of the future import, 5.0 // 2
will return 2.0
since that's the floor division result of the operation.
解決方案:
將出錯程式碼行改為:
ls = np.hstack((la[:, 0:cols // 2], lb[:, cols // 2:]))
相關文章
- python報錯:TypeError: slice indices must be integers or None or have an __index__ methodPythonErrorNoneIndex
- SAP錯誤提示解決辦法
- This function has none of DETEMINISTIC,NO SQL錯誤解決辦法FunctionNoneSQL
- Xamarin提示安裝包錯誤解決辦法
- Win7安裝錯誤提示與解決辦法Win7
- 【git】Git commit時提示錯誤時 解決辦法GitMIT
- MYSQL錯誤程式碼:1248 Every derived table must have its own alias 解決MySql
- This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de 錯誤解決辦法FunctionNoneSQL
- Python——Output not utf-8錯誤解決辦法Python
- dns錯誤怎麼辦 dns錯誤的解決辦法DNS
- 連線oracle錯誤解決辦法Oracle
- nginxFastCGI錯誤Primaryscriptunknown解決辦法NginxAST
- Unable to locate package錯誤解決辦法Package
- oracle 1455 錯誤解決辦法Oracle
- 畢設之錯誤解決辦法
- Steam錯誤程式碼138怎麼辦?無法訪問社群提示138錯誤解決方法
- Ubuntu 安裝包時提示錯誤E: Unable to locate package mysql-server錯誤 解決辦法UbuntuPackageMySqlServer
- Idea編譯錯誤解決辦法Idea編譯
- PHP編譯錯誤及解決辦法PHP編譯
- scp出現錯誤的解決辦法
- samba一個錯誤的解決辦法!Samba
- ORA-29339錯誤解決辦法
- ORA-54013錯誤解決辦法
- 解決 TypeError: Type aliases cannot be used with isinstance(). 辦法Error
- 【python】解決sys:1: DeprecationWarning:錯誤提示Python
- iOS路上遇到的錯誤及解決辦法iOS
- ubuntu下import matplotlib錯誤解決辦法UbuntuImport
- ORA-12705,錯誤的解決辦法
- OpenCV1.0編譯錯誤解決辦法OpenCV編譯
- ORA-32004錯誤解決辦法
- SPFILE引數修改錯誤的解決辦法
- ORA-12170錯誤的解決辦法
- ORA-01846錯誤解決辦法
- Mysql出現連線錯誤解決辦法MySql
- EM報錯:需要HOST Credentials驗證,但輸入什麼都提示錯誤 解決辦法
- python3中輸出錯誤怎麼辦?Python
- 執行 valet 提示 sudo 問題和 undefined function Valet\collect () 錯誤的解決辦法UndefinedFunction
- ORA-39006錯誤原因及解決辦法