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

  • Python Data Analysis
  • Ivan Idris
  • 165字
  • 2021-08-05 17:31:51

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 2 x 2 matrix again (see the elementselection.py file in this book's code bundle):

In: a = 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:

主站蜘蛛池模板: 盐池县| 卓尼县| 荃湾区| 车致| 泽库县| 白玉县| 淄博市| 汾西县| 敖汉旗| 盐津县| 凤阳县| 偏关县| 丘北县| 安新县| 项城市| 天水市| 滁州市| 卢湾区| 札达县| 疏附县| 西城区| 茶陵县| 兴隆县| 资阳市| 驻马店市| 石屏县| 双牌县| 石泉县| 东阿县| 德惠市| 泽库县| 邵阳市| 曲周县| 吉水县| 西充县| 昌宁县| 师宗县| 哈尔滨市| 大姚县| 浙江省| 伊吾县|