By selecting the 0th column in particular, as you've noticed, you reduce the dimensionality:
>>> m = np.random.normal(0, 1, size=(5, 2))
>>> m[:,0].shape
(5,)
You have a lot of options to get a 5x1 object back out. You can index using a list, rather than an integer:
>>> m[:, [0]].shape
(5, 1)
You can ask for "all the columns up to but not including 1":
>>> m[:,:1].shape
(5, 1)
Or you can use None (or np.newaxis), which is a general trick to extend the dimensions:
>>> m[:,0,None].shape
(5, 1)
>>> m[:,0][:,None].shape
(5, 1)
>>> m[:,0, None, None].shape
(5, 1, 1)
Finally, you can reshape:
>>> m[:,0].reshape(5,1).shape
(5, 1)
but I'd use one of the other methods for a case like this.
Answer from DSM on Stack OverflowW3Schools
w3schools.com › python › numpy › numpy_array_shape.asp
NumPy Array Shape
NumPy arrays have an attribute called shape that returns a tuple with each index having the number of corresponding elements. ... The example above returns (2, 4), which means that the array has 2 dimensions, where the first dimension has 2 ...
Programiz
programiz.com › python-programming › numpy › methods › shape
NumPy shape() | Programiz
August 30, 2023 - # shape of array1 shape1 = np.shape(array1) print('Shape of the first array : ', shape1)
NumPy
numpy.org › doc › stable › reference › generated › numpy.ndarray.shape.html
numpy.ndarray.shape — NumPy v2.5 Manual
Method similar to setting shape. ... Try it in your browser! >>> import numpy as np >>> x = np.array([1, 2, 3, 4]) >>> x.shape (4,) >>> y = np.zeros((2, 3, 4)) >>> y.shape (2, 3, 4)
NumPy
numpy.org › devdocs › reference › generated › numpy.ndarray.shape.html
numpy.ndarray.shape — NumPy v2.6.dev0 Manual
Method similar to setting shape. ... Try it in your browser! >>> import numpy as np >>> x = np.array([1, 2, 3, 4]) >>> x.shape (4,) >>> y = np.zeros((2, 3, 4)) >>> y.shape (2, 3, 4)
Hyperskill
hyperskill.org › university › numpy › numpy-array-shape
NumPy Array Shape
September 4, 2024 - You can change the shape of a NumPy array using the .reshape() method, which takes a tuple representing the new shape. For example, to reshape a 2D array with 4 rows and 3 columns into a 3D array with dimensions 2x2x3, use .reshape((2, 2, 3)).
NumPy
numpy.org › devdocs › reference › generated › numpy.shape.html
numpy.shape — NumPy v2.6.dev0 Manual
>>> a = np.array([(1, 2), (3, 4), (5, 6)], ... dtype=[('x', 'i4'), ('y', 'i4')]) >>> np.shape(a) (3,) >>> a.shape (3,)
Educative
educative.io › answers › how-to-return-the-shape-of-an-array-in-python
How to return the shape of an array in Python
The shape of an array is the number of elements found in each axis (rows and columns) of the array. For example, an array with a shape, (2, 3), means that the array has 2 rows that contain 3 elements each.
Real Python
realpython.com › numpy-reshape
Using NumPy reshape() to Change the Shape of an Array – Real Python
July 20, 2026 - The main data structure you’ll use in NumPy, Python’s core library for numerical computing, is the N-dimensional array. Sometimes you need to reorganize the values in a NumPy array into a different layout. That’s what NumPy’s reshape() is for. It changes an array’s shape without changing its data, so you can fit the same values into whatever configuration your program needs.
Codecademy
codecademy.com › docs › python:numpy › ndarray › .shape
Python:NumPy | ndarray | .shape | Codecademy
October 30, 2025 - For a 2D array, it returns two values i.e. rows and columns (e.g., (3, 4)). For higher dimensions, it includes one integer per axis. The following example demonstrates how to use the .shape attribute to get the dimensions of different ndarrays: ... Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python...
Medium
medium.com › @amit25173 › numpy-shape-in-python-6cfe7cb20084
numpy.shape in Python. If you think you need to spend $2,000… | by Amit Yadav | Medium
February 9, 2025 - The shape attribute outputs (2, 3), which is a tuple. This tells you that your array has 2 rows and 3 columns. Simple, right? ... Imagine you’re working on a big project — maybe analyzing some sales data or building a machine-learning model. You need to know the structure of your data to make sure it’s compatible with the operations you’re performing. For example, you can’t add two arrays together unless their shapes match.
Python Guides
pythonguides.com › python-numpy-shape
NumPy Shape And Array Dimensions In Python
May 8, 2025 - 1D [10 20 30] shape (3,) ndim 1 2D [[1,2,3],[4,3,6]] shape (2, 3) ndim 2 3D arange(24) shape (2, 3, 4) ndim 3 0D just 7 shape () ndim 0 read the tuple outside-in: the 3D array holds 2 blocks, each block has 3 rows, and each row has 4 numbers. A one dimensional array gives (3,). That trailing comma looks like a typo but it is Python’s way of writing a one-element tuple, and it is how you tell (3,) apart from the plain number 3.
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.ndarray.shape.html
numpy.ndarray.shape — NumPy v2.2 Manual
Method similar to setting shape. ... >>> import numpy as np >>> x = np.array([1, 2, 3, 4]) >>> x.shape (4,) >>> y = np.zeros((2, 3, 4)) >>> y.shape (2, 3, 4) >>> y.shape = (3, 8) >>> 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., 0.]]) >>> y.shape = (3, 6) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: total size of new array must be unchanged >>> np.zeros((4,2))[::2].shape = (-1,) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: Incompatible shape for in-place modification.
Medium
medium.com › @techwithjulles › numpy-arrays-array-shape-and-dimensions-879b7592cf44
Numpy Arrays — Array Shape and Dimensions | by TechwithJulles | Medium
November 16, 2023 - Understanding array shape and dimensions is essential when working with NumPy arrays. In this article, we covered how to determine the shape and dimensions of a NumPy array, as well as how to change the shape of an array using the .reshape() method. We also discussed different examples of arrays with different shapes and dimensions.
Interactive Chaos
interactivechaos.com › en › python › function › ndarrayshape
ndarray.shape | Interactive Chaos
January 21, 2019 - We can use the attribute to resize a numpy array. For example, in this case we start with a one-dimensional array and six elements, and convert it into a two-dimensional array of size (3, 2):
CodeSignal
codesignal.com › learn › courses › numpy-basics › lessons › array-shape-and-reshape
Array Shape and Reshape | CodeSignal Learn
With NumPy's reshape method, we can flexibly change an array's shape without altering its data. Python · import numpy as np # An array of toys toys = np.array(['teddy bear', 'robot', 'doll', 'ball', 'yo-yo', 'car']) # Reshape the array toys_boxes = toys.reshape(3, 2) # Print the reshaped array print(toys_boxes) # [['teddy bear' 'robot'] # ['doll' 'ball'] # ['yo-yo' 'car']] Reshaping arrays can be powerful in real-life scenarios. For example, if we're arranging alphabet blocks into a grid for a word puzzle, or if we're organizing family age data from a 1D array into a 2D array of generations and siblings.
YouTube
youtube.com › watch
Array Shape in Numpy | Python Numpy Array Shape | Numpy Shape of Array | Numpy Tutorial - YouTube
The shape of an array can be defined as the number of elements in each dimension. Dimension is the number of indices or subscripts, that we require in order ...
Published: August 23, 2021