def as3D(x):
""" Convert input into to 3D numpy array.
Returns
-------
x : 3D array
Examples
-------
>>> as3D(5)
array([[[5]]])
>>> as3D([1,2,3])
array([[[1, 2, 3]]])
>>> as3D([[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 < 3:
x = x[np.newaxis, :]
return x
评论列表
文章目录