在python使用中經常會用到array類型的數據,但是如何給裏面的元素添加或者去掉其中的一個或兩個方括號呢?
使用工具
Python.3.7
設定得到a的值爲
>>a
[[113 50]]
添加方括號
如果直接給a加方括號,則得到,
>>[a]
[array([[717, 628]], dtype=int32)]
這樣是錯誤的,應該通過array()函數,
>>import numpy as np
>>np.array([a])
array([[[717, 628]]], dtype=int32)
去掉方括號
去掉方括號就比較簡單一些,
>>a[0]
array([717, 628], dtype=int32)
寫於關雎
新浪微博:https://weibo.com/tianzhejia
CSDN博客:https://blog.csdn.net/qq_35605018
博客網站:http://www.zhijiadeboke.xyz
GitHub:https://github.com/ZhijiaTian
QQ郵箱:[email protected]
126郵箱:[email protected]
Outlook郵箱:[email protected]
以上均可與本人取得聯繫,歡迎探討。^ v ^