Convert inputs to arrays in julia

Viewed 123
1 Answers

Looking at the Python Numpy docs this needs to be defined as:

atleast_2d(a) = fill(a,1,1)
atleast_2d(a::AbstractArray) = ndims(a) == 1 ? reshape(a, :, 1) : a

Testing:

julia> atleast_2d(3)
1×1 Matrix{Int64}:
 3

julia> atleast_2d([4,5])
2×1 Matrix{Int64}:
 4
 5
Related