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

  • Python Data Analysis
  • Ivan Idris
  • 150字
  • 2021-08-05 17:31:50

Creating a multidimensional array

Now that we know how to create a vector, we are set to create a multidimensional NumPy array. After we produce the matrix, we will again need to show its shape (check arrayattributes.py from this book's code bundle), as demonstrated in the following code snippets:

  1. Create a multidimensional array as follows:
    In: m = array([arange(2), arange(2)])
    In: m
    Out:
    array([[0, 1],
           [0, 1]])
  2. Show the array shape as follows:
    In: m.shape
    Out: (2, 2)

We made a 2 x 2 array with the arange() subroutine. The array() function creates an array from an object that you pass to it. The object has to be an array, for example, a Python list. In the previous example, we passed a list of arrays. The object is the only required parameter of the array() function. NumPy functions tend to have a heap of optional arguments with predefined default options.

主站蜘蛛池模板: 盐边县| 淅川县| 安塞县| 毕节市| 靖州| 丰原市| 五大连池市| 环江| 突泉县| 大同县| 承德县| 濉溪县| 金秀| 米林县| 宁蒗| 长顺县| 大余县| 北京市| 靖远县| 定日县| 云安县| 太仆寺旗| 星子县| 巴中市| 宁德市| 个旧市| 额济纳旗| 开封县| 华池县| 新和县| 永泰县| 嵊泗县| 盱眙县| 龙山县| 甘泉县| 永平县| 时尚| 岳西县| 正定县| 峨山| 安塞县|