在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ 數(shù)據(jù)分析&挖掘/ NumPy數(shù)組屬性
NumPy位操作
NumPy數(shù)學(xué)算數(shù)函數(shù)
NumPy高級索引
NumPy環(huán)境安裝配置
NumPy IO文件操作
NumPy字符串函數(shù)
NumPy切片和索引
NumPy統(tǒng)計(jì)函數(shù)
NumPy矩陣庫
NumPy數(shù)組創(chuàng)建例程
NumPy線性代數(shù)
NumPy Matplotlib庫
NumPy教程
NumPy排序、搜索和計(jì)數(shù)函數(shù)
NumPy字節(jié)交換
NumPy Ndarray對象
NumPy數(shù)組操作
NumPy使用 Matplotlib 繪制直方圖
NumPy數(shù)組屬性
NumPy廣播
NumPy來自現(xiàn)有數(shù)據(jù)的數(shù)組
NumPy副本和視圖
NumPy在數(shù)組上的迭代
NumPy來自數(shù)值范圍的數(shù)組
NumPy算數(shù)運(yùn)算
NumPy數(shù)據(jù)類型

NumPy數(shù)組屬性

NumPy - 數(shù)組屬性

這一章中,我們會討論 NumPy 的多種數(shù)組屬性。

ndarray.shape

這一數(shù)組屬性返回一個包含數(shù)組維度的元組,它也可以用于調(diào)整數(shù)組大小。

示例 1

import numpy as np 
a = np.array([[1,2,3],[4,5,6]])  
print a.shape

輸出如下:

(2, 3)

示例 2

# 這會調(diào)整數(shù)組大小  
import numpy as np 

a = np.array([[1,2,3],[4,5,6]]) a.shape =  (3,2)  
print a

輸出如下:

[[1, 2] 
 [3, 4] 
 [5, 6]]

示例 3

NumPy 也提供了reshape函數(shù)來調(diào)整數(shù)組大小。

import numpy as np 
a = np.array([[1,2,3],[4,5,6]]) 
b = a.reshape(3,2)  
print b

輸出如下:

[[1, 2] 
 [3, 4] 
 [5, 6]]

ndarray.ndim

這一數(shù)組屬性返回?cái)?shù)組的維數(shù)。

示例 1

# 等間隔數(shù)字的數(shù)組  
import numpy as np 
a = np.arange(24)  print a

輸出如下:

[0 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16 17 18 19 20 21 22 23]

示例 2

# 一維數(shù)組  
import numpy as np 
a = np.arange(24) a.ndim 
# 現(xiàn)在調(diào)整其大小
b = a.reshape(2,4,3)  
print b 
# b 現(xiàn)在擁有三個維度

輸出如下:

[[[ 0,  1,  2] 
  [ 3,  4,  5] 
  [ 6,  7,  8] 
  [ 9, 10, 11]]  
  [[12, 13, 14] 
   [15, 16, 17]
   [18, 19, 20] 
   [21, 22, 23]]]

numpy.itemsize

這一數(shù)組屬性返回?cái)?shù)組中每個元素的字節(jié)單位長度。

示例 1

# 數(shù)組的 dtype 為 int8(一個字節(jié))  
import numpy as np 
x = np.array([1,2,3,4,5], dtype = np.int8)  
print x.itemsize

輸出如下:

1

示例 2

# 數(shù)組的 dtype 現(xiàn)在為 float32(四個字節(jié))  
import numpy as np 
x = np.array([1,2,3,4,5], dtype = np.float32)  
print x.itemsize

輸出如下:

4

numpy.flags

ndarray對象擁有以下屬性。這個函數(shù)返回了它們的當(dāng)前值。

序號 屬性及描述
1. C_CONTIGUOUS (C) 數(shù)組位于單一的、C 風(fēng)格的連續(xù)區(qū)段內(nèi)
2. F_CONTIGUOUS (F) 數(shù)組位于單一的、Fortran 風(fēng)格的連續(xù)區(qū)段內(nèi)
3. OWNDATA (O) 數(shù)組的內(nèi)存從其它對象處借用
4. WRITEABLE (W) 數(shù)據(jù)區(qū)域可寫入。 將它設(shè)置為flase會鎖定數(shù)據(jù),使其只讀
5. ALIGNED (A) 數(shù)據(jù)和任何元素會為硬件適當(dāng)對齊
6. UPDATEIFCOPY (U) 這個數(shù)組是另一數(shù)組的副本。當(dāng)這個數(shù)組釋放時,源數(shù)組會由這個數(shù)組中的元素更新

示例

下面的例子展示當(dāng)前的標(biāo)志。

import numpy as np 
x = np.array([1,2,3,4,5])  
print x.flags

輸出如下:

C_CONTIGUOUS : True 
F_CONTIGUOUS : True 
OWNDATA : True 
WRITEABLE : True 
ALIGNED : True 
UPDATEIFCOPY : False