Numpy ones()

numpy.ones(shape, dtype=None, order='C')
Return ndarray of input shape, filled with ones.
shapeInt, or sequence ( 2,3) , the shape of the output
dtypedata-type( Optional ), Data Type of returned array.
order{'C','F'} Optional, how the output is to be stored. C- style or Fortan style
Ones array of shape(3,4)Ones array of shape(4,3)
Shape: (3, 4)
Dimension 2
Shape: (4, 3)
Dimension 2

Using shape

Read more on shape
import numpy as np
my=np.ones(4)
print(my)
Output
[1. 1. 1. 1.]
Let us use different value for shape
my=np.ones((4,2))
Output
[[1. 1.]
 [1. 1.]
 [1. 1.]
 [1. 1.]]

dtype

We will try to return string dtype
import numpy as np
my=np.ones(4,dtype=str)
print(my)
Output
['1' '1' '1' '1']
dtype=float
my=np.ones(4,dtype=float)
Output
[1. 1. 1. 1.]
dtype=int
my=np.ones(4,dtype=int)
Output
[1 1 1 1]
Numpy eye() bincount() arange() linspace() Advanced Array creation
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer