我有两个具有相同维度的数组:
a1 = [1,1,3,4,6,6]
a2 = [1,2,3,4,5,6]
Run Code Online (Sandbox Code Playgroud)
我想根据数组对它们进行分组,a1并获得a2每个组的数组平均值。我的输出来自 array a2,如下所述:
result:
1.5
3.0
4.0
5.5
Run Code Online (Sandbox Code Playgroud)
请提出一种实现此任务的方法。谢谢!!
我想知道如何将以下代码中的数据绘制为3D-surface?
using Plots
function f(x)
x1=x[1]
x2=x[2]
sin(x[1]) + cos(x[2])
end
#Sampling
function sam()
x = range(0, 10.0, length = 9) |> collect
y = range(0, 10.0, length = 9) |> collect
tuple = zip(x,y) |> collect
return tuple
end
xy = sam()
z = f.(xy)
plot(getindex.(xy,1),getindex.(xy,2),z)
Run Code Online (Sandbox Code Playgroud)
我尝试st=:surface在plots()函数中使用gr()和pyplot()作为后端,但它不起作用。我可以知道如何将其绘制为x,y,z限制内的表面吗?
我想知道,np.meshgrid()Julia 中的 NumPy-Python是否有替代品?
#Python 参考:https ://numpy.org/doc/stable/reference/generated/numpy.meshgrid.html
我使用以下代码创建一个使用数组作为键和值的字典。
例如:
k = [1,2,3,4]
v = [2,3,4,5]
for i in 1:length(k)
get!(d, k[i], v[i])
end
#Output
Dict{Int64,Int64} with 4 entries:
4 => 5
2 => 3
3 => 4
1 => 2
Run Code Online (Sandbox Code Playgroud)
我可以知道是否有更简单的方法(最好是单行)来实现此操作?
谢谢!
我可以知道如何在 Julia 中的数据帧上应用多级索引吗?或者有没有其他方法、途径或方案来实现这一目标。
示例Python代码:
import numpy as np
import pandas as pd
arrays = [np.array(["bar", "bar", "baz", "baz", "foo", "foo", "qux", "qux"]),
np.array(["one", "two", "one", "two", "one", "two", "one", "two"]), ]
df = pd.DataFrame(np.random.randn(8, 4), index=arrays)
df
Run Code Online (Sandbox Code Playgroud)
输出:->
谢谢!!
julia ×5
arrays ×1
dataframe ×1
dictionary ×1
group-by ×1
mesh ×1
multi-index ×1
numpy ×1
plots.jl ×1