numpy.ones(shape, dtype=None, order='C')
Return ndarray of input shape, filled with ones.
shape | Int, or sequence ( 2,3) , the shape of the output |
dtype | data-type( Optional ), Data Type of returned array. |
order | {'C','F'} Optional, how the output is to be stored. C- style or Fortan style |
Shape: (3, 4) Dimension 2 | Shape: (4, 3) Dimension 2 |
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.]]
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]
Numpyeye()
bincount()
arange()
linspace()