This post was temporarily hidden by the community for possibly being offtopic, inappropriate, or spammy.
I can’t reproduce your problem. If I make a 3d array with sol = rand(2,4412,1000)
, then mean(sol, dim=2)
gives a MethodError
because the keyword is spelled dims
, not dim
. If I use the correct spelling, it works fine:
julia> using Statistics
julia> sol = rand(2,4412,1000);
julia> mean(sol, dims=3)
2×4412×1 Array{Float64, 3}:
[:, :, 1] =
0.488939 0.483749 0.499478 0.502813 … 0.494693 0.50745 0.482576
0.522986 0.515288 0.510555 0.492776 0.486172 0.493854 0.508768
Are you using some other implementation of mean
than the one in the Statistics
standard library?
General comments:

Don’t post screenshots, post quoted code.

Post a complete reproducible example, like the code I posted. See Please read: make it easier to help you
Yes I’m using the mean in the Statistics Library.
I changed the “dim” to “dims” and the result still like this…
# using Pkg
# Pkg.add("DifferentialEquations")
# Pkg.add("StochasticDelayDiffEq")
using DifferentialEquations, StochasticDelayDiffEq, Plots, Statistics
function f(du, u, h, p, t)
M_A, M_B = u;
tau, mu, n, P0, b, sigma_A, sigma_B = p;
hist_A = h(p, ttau)[1];
hist_B = h(p, ttau)[2];
du[1] = mu*M_A + (1+b)*(1/(1+(hist_B/P0)^n));
du[2] = mu*M_B + (1/(1+(hist_A/P0)^n));
end
function g(du, u, h, p, t)
tau, mu, n, P0, b, sigma_A, sigma_B = p;
du[1] = sigma_A;
du[2] = sigma_B;
end
h(p, t) = zeros(2);
tau = 100; lag = [tau];
P0 = 0.1; n = 5;
mu = 0.03; b = 0.01;
sigma_A = 0.003; sigma_B = 0.003; # only sigma < 0.07 show realiable staeady states
p = (tau, mu, n, P0, b, sigma_A, sigma_B);
tspan = (0, 50000);
u0 = [0, 0];
prob = SDDEProblem(f, g, u0, h, tspan, p; constant_lags = lag);
# single trajectory
# sol = solve(prob, RKMil());
# plot(sol)
# small multiple trajectories
# multiple trajectories
ensembleprob = EnsembleProblem(prob);
sol = solve(ensembleprob, RKMil(), EnsembleThreads(), trajectories = 1000);
# summ = EnsembleSummary(sol, 0:1:50000);
# plot(summ)
m_sol = mean(sol ,dims = 3)
# plot(sol[1, :, 1], sol[2, :, 1], xlabel = "mRNA in cell A", ylabel = "mRNA in cell B")
Sorry for posting screen shot.
This is the code
And also the “sol” is not a matrix. It’s an EnsembleSolution.
Is it because its a EnsembleSolution so I can’t use “mean”?
Thank you
typeof(sol) is an EmsembleSolution.
I wanted to plot the average trajectory. I should use EnsembleSummary(sol) to get its average trajectories then plot(…, :).