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

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:

主站蜘蛛池模板: 浦江县| 公主岭市| 山阴县| 梅河口市| 安宁市| 屏边| 南投市| 乾安县| 漳平市| 同江市| 莫力| 台北市| 同仁县| 城口县| 沁水县| 娄底市| 新乡县| 定兴县| 安阳市| 乌鲁木齐县| 锦州市| 婺源县| 西充县| 昭通市| 莎车县| 河津市| 南和县| 泗水县| 兴宁市| 大方县| 余庆县| 班戈县| 什邡市| 休宁县| 皮山县| 叙永县| 五台县| 巴东县| 巨鹿县| 衡山县| 山阴县|