ndim array - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: ndim array (/thread-41878.html) |
ndim array - Sowmya - Apr-01-2024 Hi all thrD = np.array([[1,2,3],[3,4,5],[1,-2,8]]) print(thrD.ndim)Output My doubts: What are dimensions in thrDWhy I am getting 2 as Output Please anyone can help me RE: ndim array - paul18fr - Apr-01-2024 Dim=2 because you're using a 2D array; in the following examples, 3 type of arrays have been defined:
import numpy as np thrD = np.array([[1,2,3], [3,4,5], [1,-2,8]]) print(f"thrD = \n{thrD}") print(f"thrd dim = {thrD.ndim}\n") Vector1 = np.array([1,2,3]) Vector2 = np.arange(3) print(f"Vector1 = {Vector1}") print(f"Vector2 = {Vector2}") print(f"vector1 dim = {Vector1.ndim} and vector2 dim = {Vector2.ndim}") Matrix3D = np.arange(27).reshape(3,3,3) print(f"Matrix3D = \n{Matrix3D}") print(f"Matrix3D dim = {Matrix3D.ndim}\n")giving
RE: ndim array - Sowmya - Apr-03-2024 Thank you! |