MCPcopy
hub / github.com/numpy/numpy / ones

Function ones

numpy/matlib.py:66–109  ·  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

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

Callers 6

test_testOddFeaturesMethod · 0.90
test_testInplaceMethod · 0.90
test_testAverage2Method · 0.90
_sanity_checkFunction · 0.70
blas_fpe_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

Used in the wild real call sites across dependent graphs

searching dependent graphs…