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

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.

主站蜘蛛池模板: 雷波县| 太原市| 思南县| 宜川县| 新巴尔虎右旗| 公主岭市| 湘西| 兴城市| 金塔县| 裕民县| 阳江市| 望奎县| 铁岭市| 灌南县| 沙湾县| 株洲市| 锦州市| 延长县| 新巴尔虎右旗| 保德县| 泸定县| 天长市| 彝良县| 扎兰屯市| 沂源县| 黑山县| 威宁| 武冈市| 上饶县| 西贡区| 江永县| 侯马市| 贵港市| 海晏县| 保靖县| 荆门市| 平邑县| 河间市| 莒南县| 安化县| 连州市|