numpy - 在 Julia 中从 python 替代 np.meshgrid()?
问题描述
我想知道,np.meshgrid()
在 Julia 中是否有任何替代 NumPy-Python 的方法?
#Python 参考:https ://numpy.org/doc/stable/reference/generated/numpy.meshgrid.html
解决方案
请记住,在 Julia 中,您通常可以避免meshgrid
使用智能广播操作。例如。f(x, y)
给定一个对标量值和两个“向量”xs
和进行操作的函数ys
,您可以编写f.(xs, ys')
以产生几乎任何结果meshgrid
都会给您和更多:
julia> xs = 0:0.5:1
0.0:0.5:1.0
julia> ys = 0.0:1.0
0.0:1.0:1.0
julia> f(x, y) = (x, y) # equivalent to meshgrid
f (generic function with 1 method)
julia> f.(xs, ys')
3×2 Matrix{Tuple{Float64, Float64}}:
(0.0, 0.0) (0.0, 1.0)
(0.5, 0.0) (0.5, 1.0)
(1.0, 0.0) (1.0, 1.0)
julia> g(x, y) = x*y # more efficient than meshgrid + product
g (generic function with 1 method)
julia> g.(xs, ys')
3×2 Matrix{Float64}:
0.0 0.0
0.0 0.5
0.0 1.0
推荐阅读
- java - 当我使用实体管理器时。createnativequery(),有没有简单的方法把查询结果放入dto或者vo
- node.js - 如何使用解析服务器更新用户类数据
- javascript - 量角器 - 由于 jasmine.DEFAULT_TIMEOUT_INTERVAL 导致竹测试失败
- c++ - 为什么要在类对象的声明中写一个“类”?
- php - 将相同的随机数写入文件并根据随机选择显示 DIV
- php - 我的公式中的 PHPExcel 常量“@”符号
- marklogic - 使用查询控制台编辑时 MarkLogic 10 文档格式更改
- css - 如何将 Height 属性添加到自定义 React 组件
- javascript - 如何将fabric js画布同步转换为具有背景的图像?
- sql - 如何更改 Laravel 中所有其他行的值?