Tag: How Do You Know The Shape and Size Of a Numpy Array ?


  • How Do You Know The Shape and Size Of a Numpy Array ?

    How Do You Know The Shape and Size Of a Numpy Array ?

    How Do You Know The Shape and Size Of a Numpy Array ? Table Of Contents: ndarray.ndim ndarray.size ndarray.shape (1) ndarray.ndim ndarray.ndim will tell you the number of axes, or dimensions, of the array. Example-1: a = np.array([1, 2, 3]) a array([1, 2, 3]) a.ndim Output: 1 Example-2: b = np.array([[1,4],[3,2]]) b array([[1, 4], [3, 2]]) b.ndim Output: 2 Example-3: c = np.array([[[1,4],[3,2]]]) c array([[[1, 4], [3, 2]]]) c.ndim Output: 3 Example-4: y = np.zeros((2, 3, 4)) y array([[[0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0.]], [[0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0.,

    Read More