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

Function as_series

numpy/polynomial/polyutils.py:84–157  ·  view source on GitHub ↗

Return argument as a list of 1-d arrays. The returned list contains array(s) of dtype double, complex double, or object. A 1-d argument of shape ``(N,)`` is parsed into ``N`` arrays of size one; a 2-d argument of shape ``(M,N)`` is parsed into ``M`` arrays of size ``N`` (i.e.,

(alist, trim=True)

Source from the content-addressed store, hash-verified

82
83
84def as_series(alist, trim=True):
85 """
86 Return argument as a list of 1-d arrays.
87
88 The returned list contains array(s) of dtype double, complex double, or
89 object. A 1-d argument of shape ``(N,)`` is parsed into ``N`` arrays of
90 size one; a 2-d argument of shape ``(M,N)`` is parsed into ``M`` arrays
91 of size ``N`` (i.e., is "parsed by row"); and a higher dimensional array
92 raises a Value Error if it is not first reshaped into either a 1-d or 2-d
93 array.
94
95 Parameters
96 ----------
97 alist : array_like
98 A 1- or 2-d array_like
99 trim : boolean, optional
100 When True, trailing zeros are removed from the inputs.
101 When False, the inputs are passed through intact.
102
103 Returns
104 -------
105 [a1, a2,...] : list of 1-D arrays
106 A copy of the input data as a list of 1-d arrays.
107
108 Raises
109 ------
110 ValueError
111 Raised when `as_series` cannot convert its input to 1-d arrays, or at
112 least one of the resulting arrays is empty.
113
114 Examples
115 --------
116 >>> from numpy.polynomial import polyutils as pu
117 >>> a = np.arange(4)
118 >>> pu.as_series(a)
119 [array([0.]), array([1.]), array([2.]), array([3.])]
120 >>> b = np.arange(6).reshape((2,3))
121 >>> pu.as_series(b)
122 [array([0., 1., 2.]), array([3., 4., 5.])]
123
124 >>> pu.as_series((1, np.arange(3), np.arange(2, dtype=np.float16)))
125 [array([1.]), array([0., 1., 2.]), array([0., 1.])]
126
127 >>> pu.as_series([2, [1.1, 0.]])
128 [array([2.]), array([1.1])]
129
130 >>> pu.as_series([2, [1.1, 0.]], trim=False)
131 [array([2.]), array([1.1, 0. ])]
132
133 """
134 arrays = [np.array(a, ndmin=1, copy=False) for a in alist]
135 if min([a.size for a in arrays]) == 0:
136 raise ValueError("Coefficient array is empty")
137 if any(a.ndim != 1 for a in arrays):
138 raise ValueError("Coefficient array is not 1-d")
139 if trim:
140 arrays = [trimseq(a) for a in arrays]
141

Callers 7

trimcoefFunction · 0.85
getdomainFunction · 0.85
_fromrootsFunction · 0.85
_divFunction · 0.85
_addFunction · 0.85
_subFunction · 0.85
_powFunction · 0.85

Calls 5

trimseqFunction · 0.85
minFunction · 0.50
anyFunction · 0.50
dtypeMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected