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

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 it, as demonstrated in the following code snippets:

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

We made a 2x2 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.

主站蜘蛛池模板: 延安市| 安丘市| 类乌齐县| 固镇县| 延庆县| 西安市| 修水县| 龙川县| 浦县| 开江县| 临泉县| 乌兰县| 浦江县| 湖州市| 昭觉县| 新营市| 台前县| 富源县| 肥乡县| 射阳县| 蒙自县| 宁晋县| 揭东县| 顺昌县| 阿拉善右旗| 霞浦县| 绍兴县| 太保市| 米易县| 阜康市| 华安县| 额敏县| 台安县| 贡嘎县| 逊克县| 天全县| 府谷县| 大名县| 包头市| 德格县| 西安市|