小编Win*_*ore的帖子

在 Julia 中使用 findfirst() 的多个条件

假设我有两个数组,如下所示:

  • x = [10, 30, 50, 99, 299]
  • y = [3, 29, 30, 23, 55]

如何找到满足以下两个条件的索引?

  • x > 80 & y > 30

因此,对于我的示例,我预计返回值为索引 5。我想格式将如下所示:

findfirst(x -> x > 80 \union y -> y> 30, x,y)

但这不起作用..

另外,在我的例子中,x 和 y 是数据框中的列,但进行索引搜索也不起作用。

findfirst julia

5
推荐指数
1
解决办法
678
查看次数

在 Julia 中向日期时间添加一个小时?

假设我有一个日期时间,我想向该日期时间添加任意时间段并获取新的日期时间。例如,我想查找除夕后 333 小时后的日期和时间。

出现两个问题:

  1. 我实际上无法创建超过 23 小时的时间
  2. 如果我确实创建了 ::Time,则无法将其添加到 ::DateTime

我的问题基本上是如何将时间加在一起?

代码

julia> dt = DateTime(2021,1)
2021-01-01T00:00:00

julia> t = Time(333)
ERROR: ArgumentError: Hour: 333 out of range (0:23)

julia> t = Time(1)
01:00:00

julia> dt + t
ERROR: MethodError: no method matching +(::DateTime, ::Time)
Closest candidates are:
  +(::Any, ::Any, ::Any, ::Any...) at operators.jl:560
Run Code Online (Sandbox Code Playgroud)

datetime date-arithmetic julia

3
推荐指数
1
解决办法
814
查看次数

朱莉娅:如何更改散点图中组的颜色

假设我有以下示例代码

using PlotlyJS
using CSV, DataFrames

df = dataset(DataFrame, "iris")
plot(
    df, x=:sepal_width, y=:sepal_length, color=:species,
    mode="markers"
)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 我该如何指定每个组的颜色,例如,如果我希望 setosa 为黄色?

这正是Plotly-Express: How to fix the color mapping when set color by column name ,但我在 julia 中需要它。我无法让 color_discrete_map 工作...

uicolor julia plotly plotly.js

3
推荐指数
1
解决办法
955
查看次数