For each element in the main argument of np.zeros the function will add a new dimension to the output vector.

Your first code np.zeros ((1,2)) yields an array with two dimensions, one element in the first dimension and two elements in the second dimension, thus

[[0.]
[0.]]

The second piece of code has only one element in the main argument, which is translated to "one single dimension, two elements in that dimension". Thus, the output to your np.zeros((2,)) will be the same as the one for np.zeros(2):

array([0., 0.])

You could try with a third dimension to see it further:

np.zeros((1,2,1))
array([[[0.],
        [0.]]])

I short, each square bracket adds to a new dimension based on the elements in the first argument of the function np.zeros.

Answer from ibarrond on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › numpy › numpy-zeros-python
numpy.zeros() in Python - GeeksforGeeks
June 15, 2026 - Example 1: This example creates a 2D array with 3 rows and 4 columns. All elements are initialized to zero. ... Explanation: np.zeros((3, 4)) creates a 2D array with 3 rows and 4 columns filled with 0.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.zeros.html
numpy.zeros — NumPy v2.1 Manual
New in version 1.20.0. ... Array of zeros with the given shape, dtype, and order. ... Return an array of zeros with shape and type of input. ... Return a new uninitialized array. ... Return a new array setting values to one. ... Return a new array of given shape filled with value. ... >>> np.zer...
🌐
Medium
medium.com › @debopamdeycse19 › python-numpy-zeros-function-with-examples-5e47cfc6e15b
Numpy np zeros() function in Python with examples | by Let's Decode | Medium
November 2, 2023 - np.zeros() function empowers you to create new arrays of specified shapes and data types, initializing all elements to zero.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ma.zeros.html
numpy.ma.zeros — NumPy v2.1 Manual
New in version 1.20.0. ... Array of zeros with the given shape, dtype, and order. ... Return an array of zeros with shape and type of input. ... Return a new uninitialized array. ... Return a new array setting values to one. ... Return a new array of given shape filled with value. ... >>> np.zer...
🌐
WildLearner
wildlearner.com › learn › course › numpy › arrays › creating-arrays › the-np-zeros-and-np-ones-methods
NumPy | WildLearner - Learn to code, and get hired.
Introduction to the course NumPy is a powerful library for the Python programming language that provides support for large, multi-dimensional arrays and matrices of numerical data, as well as a large collection of mathematical functions to operate on these arrays.
Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › numpy-zeros-in-python
numpy.zeros() in Python | DigitalOcean
Technical tutorials, Q&A, events — This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.
🌐
AskPython
askpython.com › python-modules › numpy › numpy-zeros-method-in-python
NumPy zeros() Method in Python - AskPython
August 6, 2022 - import numpy as np arr = np.zeros( shape , dtype , order ) ... The shape is an integer of sequence, which decides the size as well as the shape of the array. When the shape is provided as an integer number, the array generated would be a 1D array.
🌐
Reddit
reddit.com › r/learnpython › eli5 the use of zeros() and ones() methods in numpy?
r/learnpython on Reddit: ELI5 the use of zeros() and ones() methods in Numpy?
June 6, 2020 -

I'm currently studying Numpy from a few different sources and all of them introduce the methods zeros() and ones() and I think I understand what they do, but the instructors never explain what the purpose of these methods is. Why would anyone ever want to use these in actual programming and what the advantages are to just using np.full( ( 2 , 2 ) , 0) or np.full( ( 2 , 2 ) , 1). I would appreciate some explanation on this part. Thanks in advance.

🌐
Linux Hint
linuxhint.com › use-python-numpy-zeros-ones-functions
How to Use Python NumPy zeros() and ones() Functions – Linux Hint
The zeros() function of the script will create a three-dimensional NumPy array float numbers. The data type and the first array’s values will be printed in the next statement based on C-style ordering. # Import NumPy import numpy as np # Create three-dimensional NumPy array using zeros() ...
🌐
Python Guides
pythonguides.com › python-numpy-zeros
Create Arrays Of Zeros In NumPy - Python Guides
May 16, 2025 - The np.zeros_like() function creates an array of zeros with the same shape and type as a given array. I find this incredibly useful when I need to create a result array that matches an input array. # Create a sample array original = np.array([[1, 2, 3], [4, 5, 6]]) # Create a zeros array with the same shape and type zeros_copy = np.zeros_like(original) print(zeros_copy) # Output: # [[0 0 0] # [0 0 0]]
🌐
Python Tutorial
pythontutorial.net › home › python numpy › numpy zeros()
NumPy zeros(): Creating an Array with a Shape & Filled with Zeros
August 16, 2022 - By default, zeros() function uses the type float64 for its elements. For example: import numpy as np a = np.zeros((2, 3)) print(a.dtype)Copy · Output: float64Copy · To use a different type, you need to explicitly specify it in the zeros() function via the dtype argument.
🌐
w3resource
w3resource.com › numpy › array-creation › zeros.php
NumPy: numpy.zeros() function - w3resource
April 21, 2026 - Returns an ndarray of zeros with the specified shape, data type, and memory layout order. ... In this example, a tuple (3, 2) defines the shape of the array, and np.zeros() creates a 2D array filled with zeros.
🌐
Python Examples
pythonexamples.org › python-numpy-zeros
Create Array with Zeros in NumPy - Examples
To create a numpy array with zeros, given shape of the array, use numpy.zeros() function. The syntax to create zeros numpy array is: numpy.zeros(shape, dtype=float, order='C')
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.zeros.html
numpy.zeros — NumPy v2.6.dev0 Manual
Added in version 1.20.0. ... Array of zeros with the given shape, dtype, and order. ... Return an array of zeros with shape and type of input. ... Return a new uninitialized array. ... Return a new array setting values to one. ... Return a new array of given shape filled with value. ... Try it in your browser! >>> import numpy as np ...
🌐
DataCamp
datacamp.com › doc › numpy › zeros
NumPy zeros()
`dtype` determines the data type ... Fortran-style column-major order. import numpy as np array_1d = np.zeros(5) This creates a one-dimensional array with 5 elements, all initialized to zero....
🌐
Codecademy
codecademy.com › docs › python:numpy › built-in functions › .zeros()
Python:NumPy | Built-in Functions | .zeros() | Codecademy
June 23, 2025 - This example creates a 1D array of five zeros and a 2D array of zeros with shape (3, 2) and integer data type using NumPy’s .zeros() function: import numpy as np · array1 = np.zeros(5) print(array1) array2 = np.zeros((3, 2), dtype=int) print(array2) Copy to clipboard ·
🌐
Medium
medium.com › @debopamdeycse19 › what-is-the-use-of-the-zeros-function-in-numpy-arrays-in-python-dde91b18e234
What is the use of the Zeros function in numpy arrays in Python? | by Let's Decode | Medium
November 28, 2023 - #creating 1-D array filled with zeros import numpy as np arr=np.zeros(5) print(arr) Output: [0.0 0.0 0.0 0.0 0.0] # Creating a 2x3 array (2 rows, 3 columns) filled with zeros import numpy as np arr = np.zeros((2, 3)) print(arr) Output: [[0.0 0.0 0.0] [0.0 0.0 0.0]] Note: For a 2D array, you would provide the shape as a tuple with two values: (rows, columns).