plot - 没有方法匹配^
问题描述
我UnitRange
在 Julia 中创建了一个并试图创建一个x
关于x
和的情节x ^ 2
。我已经编写了以下代码。
x = [-10:10]
p1 = plot(x, x)
p2 = plot(x, x.^2)
我收到以下错误:
MethodError: no method matching ^(::UnitRange{Int64}, ::Int64)
Closest candidates are:
^(!Matched::Float16, ::Integer) at math.jl:795
^(!Matched::Missing, ::Integer) at missing.jl:120
^(!Matched::Missing, ::Number) at missing.jl:93
...
Stacktrace:
[1] _broadcast_getindex at ./none:0 [inlined]
[2] getindex at ./broadcast.jl:515 [inlined]
[3] copy at ./broadcast.jl:790 [inlined]
[4] materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Nothing,typeof(Base.literal_pow),Tuple{Base.RefValue{typeof(^)},Array{UnitRange{Int64},1},Base.RefValue{Val{2}}}}) at ./broadcast.jl:756
[5] top-level scope at In[18]:3
我的代码有什么错误?
解决方案
你可以改变:
x.^2
至:
x[1].^2
推荐阅读
- python - 尝试检查另一个熊猫列中是否存在值时出现长度错误
- python - Pandas Dataframe - 对于每一行,返回具有重叠日期的其他行的计数
- swift - 将屏幕坐标转换为 Metal 的标准化设备坐标
- mysql - 为sql更新中的所有列值连接一个字符串
- python - 使用 Python 在单个列条目上组合两个 FITS 表
- c# - c# 在字符串中查找关键字并将其删除
- vba - 从 Access 子窗体中提取数据:运行时错误 438
- spring - DataMongoTest 加载拦截器
- rust - 在 Rust 中格式化 const 字符串
- java - 如何配置休眠以在 Spring Boot 中使用 Spring Data save 和 Session Factory with Criteria API