MCPcopy Create free account
hub / github.com/numpy/numpy / ones

Function ones

numpy/matlib.py:62–105  ·  view source on GitHub ↗

Matrix of ones. Return a matrix of given shape and type, filled with ones. Parameters ---------- shape : {sequence of ints, int} Shape of the matrix dtype : data-type, optional The desired data-type for the matrix, default is np.float64. order : {'C', '

(shape, dtype=None, order='C')

Source from the content-addressed store, hash-verified

60 return ndarray.__new__(matrix, shape, dtype, order=order)
61
62def ones(shape, dtype=None, order='C'):
63 """
64 Matrix of ones.
65
66 Return a matrix of given shape and type, filled with ones.
67
68 Parameters
69 ----------
70 shape : {sequence of ints, int}
71 Shape of the matrix
72 dtype : data-type, optional
73 The desired data-type for the matrix, default is np.float64.
74 order : {'C', 'F'}, optional
75 Whether to store matrix in C- or Fortran-contiguous order,
76 default is 'C'.
77
78 Returns
79 -------
80 out : matrix
81 Matrix of ones of given shape, dtype, and order.
82
83 See Also
84 --------
85 ones : Array of ones.
86 matlib.zeros : Zero matrix.
87
88 Notes
89 -----
90 If `shape` has length one i.e. ``(N,)``, or is a scalar ``N``,
91 `out` becomes a single row matrix of shape ``(1,N)``.
92
93 Examples
94 --------
95 >>> np.matlib.ones((2,3))
96 matrix([[1., 1., 1.],
97 [1., 1., 1.]])
98
99 >>> np.matlib.ones(2)
100 matrix([[1., 1.]])
101
102 """
103 a = ndarray.__new__(matrix, shape, dtype, order=order)
104 a.fill(1)
105 return a
106
107def zeros(shape, dtype=None, order='C'):
108 """

Callers 5

test_testOddFeaturesMethod · 0.90
test_testInplaceMethod · 0.90
test_testAverage2Method · 0.90
_sanity_checkFunction · 0.70
testOnesMethod · 0.50

Calls 1

__new__Method · 0.45

Tested by 4

test_testOddFeaturesMethod · 0.72
test_testInplaceMethod · 0.72
test_testAverage2Method · 0.72
testOnesMethod · 0.40