def as2D(x):
""" Convert input into to 2D numpy array.
Returns
-------
x : 2D array
Examples
-------
>>> as2D(5)
array([[5]])
>>> as2D([1,2,3])
array([[1, 2, 3]])
>>> as2D([[3,4,5,6]])
array([[3, 4, 5, 6]])
"""
if not isinstance(x, np.ndarray):
x = np.asarray_chkfinite(x)
if x.ndim < 1:
x = np.asarray_chkfinite([x])
while x.ndim < 2:
x = x[np.newaxis, :]
return x
评论列表
文章目录