官术网_书友最值得收藏!

Selecting NumPy array elements

From time to time, we will wish to select a specific constituent of an array. We will take a look at how to do this, but to kick off, let's make a 2x2 matrix again:

In: a = np.array([[1,2],[3,4]]) 
In: a 
Out: 
array([[1, 2], 
       [3, 4]]) 

The matrix was made this time by giving the array() function a list of lists. We will now choose each item of the matrix one at a time, as shown in the following code snippet. Recall that the index numbers begin from 0:

In: a[0,0] 
Out: 1 
In: a[0,1] 
Out: 2 
In: a[1,0] 
Out: 3 
In: a[1,1] 
Out: 4 

As you can see, choosing elements of an array is fairly simple. For the array a, we just employ the notation a[m,n], where m and n are the indices of the item in the array. Have a look at the following figure for your reference:

主站蜘蛛池模板: 开原市| 项城市| 孟津县| 日喀则市| 兴安县| 庆安县| 天水市| 屏南县| 贡嘎县| 东丰县| 西充县| 延庆县| 中超| 冕宁县| 应城市| 汉沽区| 桃园县| 肃南| 繁昌县| 太湖县| 嵩明县| 五莲县| 韩城市| 衢州市| 广州市| 隆昌县| 屯门区| 中方县| 乌什县| 蒲江县| 吉隆县| 望城县| 胶州市| 甘肃省| 剑阁县| 涿鹿县| 平武县| 准格尔旗| 瑞金市| 宁蒗| 绥德县|