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

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.

主站蜘蛛池模板: 扶沟县| 商城县| 苏尼特右旗| 庄浪县| 潞西市| 将乐县| 克东县| 正阳县| 雷山县| 曲松县| 北碚区| 富民县| 平塘县| 台江县| 兴城市| 临江市| 巨鹿县| 麻栗坡县| 靖边县| 岳池县| 福州市| 丁青县| 二手房| 澄江县| 阿拉尔市| 静乐县| 昭平县| 策勒县| 友谊县| 凌海市| 射洪县| 壤塘县| 榕江县| 米林县| 平安县| 轮台县| 丽江市| 轮台县| 攀枝花市| 民和| 夏河县|