Numpy ones()

Numpy

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

Using 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()


plus2net.com



Post your comments , suggestion , error , requirements etc here




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