1樓:
參考旁徵勃引的答案
numpy官網教程(NumPy quickstart)裡面關於ndim的定義:
ndarray.ndim:the number of axes (dimensions) of the array.
另外ndarray.shape也提到了ndim:
the dimensions of the array. This is a tuple of integers indicating the size of the array in each dimension. For a matrix with n rows and m columns, shape will be (n,m).
The length of the shape tuple is therefore the number of axes, ndim.
把numpy裡面的array理解成數學上的張量(tensor)就好了,ndim:張量的維度(階或者秩)。
ndarray.shape:通俗點說起來,shape(翻譯成規格?
)是對張量維度的詳細描述,比如矩陣是2階張量(ndim=2),但是具體是怎樣的矩陣,或者說怎樣的2階張量,就可以用shape詳細描述,比如2*3的矩陣對應的shape為(2,3),還是4*2的矩陣對應的shape為(4,2)
2樓:旁徵勃引
一句話解釋:ndarray 的 ndim 屬性表示的是多維陣列的維度。
ndim == 1 ,代表這個 ndarray 是乙個一維陣列(向量);
ndim == 2 ,代表這個 ndarray 是乙個二維陣列(矩陣);
ndim == 3 ,代表這個 ndarray 是乙個三維陣列(張量) 。
其實,如果 ndim == 0,這時候 ndarray 物件就代表乙個標量了,
但由於無任何元素的 ndarray 是乙個空陣列(可以理解為乙個指向任意方向的零向量),所以始終有 ndim >= 1。
3樓:陳文
今天剛好也遇到了這個問題。shape裡面有幾個數字,ndim就是多少
4樓:youw3
ndarray的shape有幾個數字, ndim就是多少
5樓:無用
ndim="有多少個維度"。
一般n在語境中表示多少,dim即是維度。
比如:import numpy as npa=np.random.ranf((7,8,9))print(a.shape)
print(a.ndim)
輸出:(7, 8, 9)
Python 中的 numpy 定義 dtype 型別後為什麼賦值32768得到的是相反數?
不中 計算機中,不管什麼語言,儲存資料都是用的二進位制數。乙個陣列就是多個二進位制數的集合。陣列中每個元素的型別表明其理解方式,包括長度及其運算方法。原來陣列的每個元素是32位的,後轉換成short即16位有符號數。這種轉換中,陣列儲存的數並未發生變化,只是理解方式不同了。比如第乙個元素其值是0x0...
python下numpy不成功,請問有沒有簡單的安裝方法?
Gxz 請問Centos 如何離線安裝Numpy Panda Scipy這些包呢?生產伺服器不允許接網路,也就不能pip install了,所以現在不知道該如何離線方式安裝呢?還請各位賜教 王潔萍 pip default timeout 100 install U numpy 遇到read time...
python除了用requests庫,還能用什麼編寫爬蟲?
Lazier aiohttp,基於asyncio的非同步HTTP框架,併發效率不錯,我在這之上封裝了乙個請求池 selenium 其實requests就基本足夠了,配合ExecJS基本能解決大部分問題.少數問題可以通過selenium解決.爬蟲關鍵的是資料整合與抽象,用什麼Web庫是底層的工具選擇....