问题描述
我有以下数据框
我想绘制Evar / (T^2 * L)
using Plots,DataFrames,CSV
@df data plot(:T,:Evar / (:T * T * :L),group=:L,legend=nothing)
MethodError: no method matching *(::Vector{Float64},::Vector{Float64})
不幸的是,我不确定如何在 plot 函数中使用运算符。
对于“/”运算符,它似乎有效,但是如果我想使用“*”进行乘法运算,则会出现上述错误。
这是我所说的“/”工作的一个例子:
解决方法
您需要对乘法和除法进行矢量化,因此将是:
@df data plot(:T,:Evar ./ (:T .* :T .* :L),group=:L,legend=nothing)
更简单的例子:
julia> a = [1,3,4];
julia> b = [4,5,6];
julia> a * b
ERROR: MethodError: no method matching *(::Vector{Int64},::Vector{Int64})
julia> a .* b
3-element Vector{Int64}:
4
15
24
这不是 /
有效,因为 /
是为向量定义的,但结果可能不是您想要的:
julia> c = a / b
3×3 Matrix{Float64}:
0.0519481 0.0649351 0.0779221
0.155844 0.194805 0.233766
0.207792 0.25974 0.311688
它只是返回矩阵,例如 c*b == a
,其中 *
是矩阵乘法。