gpt4 book ai didi

numpy - 将输入转换为 julia 中的数组

转载 作者:行者123 更新时间:2023-12-03 23:40:35 27 4
gpt4 key购买 nike

是否有替代 numpy.atleast_2d() 的替代方案?在 Julia 。
python函数可以在这个链接上找到:https://www.geeksforgeeks.org/numpy-atleast_2d-in-python/

最佳答案

查看 Python Numpy 文档,这需要定义为:

atleast_2d(a) = fill(a,1,1)
atleast_2d(a::AbstractArray) = ndims(a) == 1 ? reshape(a, :, 1) : a
测试:
julia> atleast_2d(3)
1×1 Matrix{Int64}:
3

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

关于numpy - 将输入转换为 julia 中的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66059325/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com