# DimensionMismatch: arrays could not be broadcast to a common size: a has axes Base.OneTo(5) and b has axes Base.OneTo(0)

**URL:** https://discourse.julialang.org/t/dimensionmismatch-arrays-could-not-be-broadcast-to-a-common-size-a-has-axes-base-oneto-5-and-b-has-axes-base-oneto-0/126193
**Category:** General Usage
**Created:** [February 22, 2025, 5:44pm UTC](https://discourse.julialang.org/t/dimensionmismatch-arrays-could-not-be-broadcast-to-a-common-size-a-has-axes-base-oneto-5-and-b-has-axes-base-oneto-0/126193 "2025-02-22T17:44:59Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Casper\_Casier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/casper_casier/32/214252_2.png) [@Casper\_Casier](https://discourse.julialang.org/u/Casper_Casier)
#### Post date: [February 22, 2025, 5:44pm UTC](https://discourse.julialang.org/t/dimensionmismatch-arrays-could-not-be-broadcast-to-a-common-size-a-has-axes-base-oneto-5-and-b-has-axes-base-oneto-0/126193/1 "2025-02-22T17:44:59Z")

</div>

Im trying to find the ODEs of some concentration profiles using SINDy.

r1 and r\_deact are known terms that can be in the ODE so I added them to the basis. (also tried already with a simpler basis but same problem). Also, the sizes of Xₙ (5, 161) and t (161,) match. What am I overseeing?

@variables u[1:5]

# Reaction rates

f\_act = u[4] / C\_sites\_0  
r1 = k1 \* u[1] \* u[3] \* W\_cat \* f\_act / (1 + K\_RNO2 \* u[1] + sqrt(K\_H \* u[3]))^3  
r\_deact = k\_deact \* u[1] \* u[4]

poly\_basis = polynomial\_basis(u, 2)

basis\_functions = vcat(poly\_basis, [r1, r\_deact])  
basis = Basis(basis\_functions, u)

Xₙ = Array(true\_solutions\_noisy[N\_values[1]])

full\_problem = ContinuousDataDrivenProblem(Xₙ, t)

λ = 1e-1  
opt = ADMM(λ)

options = DataDrivenCommonOptions(maxiters = 10\_000,  
normalize = DataNormalization(ZScoreTransform),  
selector = bic, digits = 1,  
data\_processing = DataProcessing(split = 0.9,  
batchsize = 200,  
shuffle = true,  
rng = StableRNG(1111)))

full\_res = solve(full\_problem, basis, opt, options = options)  
full\_eqs = get\_basis(full\_res)  
println(full\_res)

---

<div class="post-metadata">

### Author: ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)
#### Post date: [February 22, 2025, 7:59pm UTC](https://discourse.julialang.org/t/dimensionmismatch-arrays-could-not-be-broadcast-to-a-common-size-a-has-axes-base-oneto-5-and-b-has-axes-base-oneto-0/126193/2 "2025-02-22T19:59:28Z")

</div>

Hi there and welcome to the Discourse 👋  
Please make your code easier to read by enclousing it in triple backticks `````  
Please include the error message as well and try to indicate which line fails if you can make it out 🙂

---

<div class="post-metadata">

### Author: ![Casper\_Casier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/casper_casier/32/214252_2.png) [@Casper\_Casier](https://discourse.julialang.org/u/Casper_Casier)
#### Post date: [February 22, 2025, 8:13pm UTC](https://discourse.julialang.org/t/dimensionmismatch-arrays-could-not-be-broadcast-to-a-common-size-a-has-axes-base-oneto-5-and-b-has-axes-base-oneto-0/126193/3 "2025-02-22T20:13:20Z")

</div>

```julia
@variables u[1:5] 

# Reaction rates
f_act = u[4] / C_sites_0
r1 = k1 * u[1] * u[3] * W_cat * f_act / (1 + K_RNO2 * u[1] + sqrt(K_H * u[3]))^3
r_deact = k_deact * u[1] * u[4]

# Define polynomial basis terms
poly_basis = polynomial_basis(u, 2)

# Include reaction rates in the basis
basis_functions = vcat(poly_basis, [r1, r_deact])
basis = Basis(basis_functions, u)

#only for 1 N value for now
Xₙ = Array(true_solutions_noisy[N_values[1]])

full_problem = ContinuousDataDrivenProblem(Xₙ, t)

λ = 1e-1
opt = ADMM(λ)

options = DataDrivenCommonOptions(maxiters = 10_000,
    normalize = DataNormalization(ZScoreTransform),
    selector = bic, digits = 1,
    data_processing = DataProcessing(split = 0.9,
        batchsize = 200,
        shuffle = true,
        rng = StableRNG(1111)))

full_res = solve(full_problem, basis, opt, options = options)
full_eqs = get_basis(full_res)
println(full_res)

```

I get the following error message when I try to run `full_res = solve(full_problem, basis, opt, options = options)`:  
ERROR: DimensionMismatch: arrays could not be broadcast to a common size: a has axes Base.OneTo(5) and b has axes Base.OneTo(0)

---

<div class="post-metadata">

### Author: ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)
#### Post date: [February 22, 2025, 8:41pm UTC](https://discourse.julialang.org/t/dimensionmismatch-arrays-could-not-be-broadcast-to-a-common-size-a-has-axes-base-oneto-5-and-b-has-axes-base-oneto-0/126193/4 "2025-02-22T20:41:04Z")

</div>

Provide the complete error message. In a code block.

---

<div class="post-metadata">

### Author: ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)
#### Post date: [February 22, 2025, 8:51pm UTC](https://discourse.julialang.org/t/dimensionmismatch-arrays-could-not-be-broadcast-to-a-common-size-a-has-axes-base-oneto-5-and-b-has-axes-base-oneto-0/126193/5 "2025-02-22T20:51:38Z")

</div>

Also this is not the full code. As the definitions of a least `true_solutions_noisy` and `N_values` are missing but I think they might be important to understand your issue.

---

<div class="post-metadata">

### Author: ![Casper\_Casier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/casper_casier/32/214252_2.png) [@Casper\_Casier](https://discourse.julialang.org/u/Casper_Casier)
#### Post date: [February 23, 2025, 7:13pm UTC](https://discourse.julialang.org/t/dimensionmismatch-arrays-could-not-be-broadcast-to-a-common-size-a-has-axes-base-oneto-5-and-b-has-axes-base-oneto-0/126193/6 "2025-02-23T19:13:34Z")

</div>

```julia
LoadError: DimensionMismatch: arrays could not be broadcast to a common size: a has axes Base.OneTo(5) and b has axes Base.OneTo(0)
Stacktrace:
  [1] _bcs1
    @ .\broadcast.jl:523 [inlined]
  [2] _bcs
    @ .\broadcast.jl:517 [inlined]
  [3] broadcast_shape
    @ .\broadcast.jl:511 [inlined]
  [4] combine_axes
    @ .\broadcast.jl:492 [inlined]
  [5] instantiate
    @ .\broadcast.jl:302 [inlined]
  [6] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{2}, Nothing, typeof(-), Tuple{Matrix{Any}, Matrix{Any}}})
    @ Base.Broadcast .\broadcast.jl:867
  [7] DataDrivenSolution(b::Basis{false, false}, p::DataDrivenProblem{Float64, false, DataDrivenDiffEq.Continuous}, alg::ADMM{Float64, Float64}, result::Vector{DataDrivenSparse.SparseRegressionResult{Matrix{Float64}, Vector{Any}, Vector{Int64}, Float64, Float64, DDReturnCode}}, internal_problem::DataDrivenDiffEq.InternalDataDrivenProblem{ADMM{Float64, Float64}, Basis{false, false}, Tuple{SubArray{Float64, 2, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, UnitRange{Int64}}, true}, SubArray{Float64, 2, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, UnitRange{Int64}}, true}}, DataLoader{Tuple{SubArray{Float64, 2, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, UnitRange{Int64}}, true}, SubArray{Float64, 2, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, UnitRange{Int64}}, true}}, StableRNGs.LehmerRNG, Val{nothing}}, ZScoreTransform{Float64, Vector{Float64}}, Matrix{Bool}, Matrix{Bool}, Vector{Bool}, Matrix{Bool}, DataDrivenCommonOptions{Float64, @NamedTuple{}}, DataDrivenProblem{Float64, false, DataDrivenDiffEq.Continuous}, @Kwargs{}}, retcode::DDReturnCode)
    @ DataDrivenDiffEq C:\Users\Casper Casier\.julia\packages\DataDrivenDiffEq\gpXhb\src\solution.jl:37
  [8] solve!(ps::DataDrivenDiffEq.InternalDataDrivenProblem{ADMM{Float64, Float64}, Basis{false, false}, Tuple{SubArray{Float64, 2, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, UnitRange{Int64}}, true}, SubArray{Float64, 2, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, UnitRange{Int64}}, true}}, DataLoader{Tuple{SubArray{Float64, 2, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, UnitRange{Int64}}, true}, SubArray{Float64, 2, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, UnitRange{Int64}}, true}}, StableRNGs.LehmerRNG, Val{nothing}}, ZScoreTransform{Float64, Vector{Float64}}, Matrix{Bool}, Matrix{Bool}, Vector{Bool}, Matrix{Bool}, DataDrivenCommonOptions{Float64, @NamedTuple{}}, DataDrivenProblem{Float64, false, DataDrivenDiffEq.Continuous}, @Kwargs{}})
    @ DataDrivenSparse C:\Users\Casper Casier\.julia\packages\DataDrivenSparse\0c4Fb\src\commonsolve.jl:21
  [9] solve(::DataDrivenProblem{Float64, false, DataDrivenDiffEq.Continuous}, ::Vararg{Any}; kwargs::@Kwargs{options::DataDrivenCommonOptions{Float64, @NamedTuple{}}})
    @ CommonSolve C:\Users\Casper Casier\.julia\packages\CommonSolve\JfpfI\src\CommonSolve.jl:23
 [10] top-level scope
    @ c:\Users\Casper Casier\Desktop\UGent\6 Master chemical engineering\Thesis\Kinetics simultaneous training.jl:341
 [11] eval
    @ .\boot.jl:430 [inlined]
 [12] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base .\loading.jl:2734
 [13] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base .\essentials.jl:1055
 [14] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base .\essentials.jl:1052
 [15] inlineeval(m::Module, code::String, code_line::Int64, code_column::Int64, file::String; softscope::Bool)
    @ VSCodeServer c:\Users\Casper Casier\.vscode\extensions\julialang.language-julia-1.127.2\scripts\packages\VSCodeServer\src\eval.jl:271
 [16] (::VSCodeServer.var"#69#74"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\Casper Casier\.vscode\extensions\julialang.language-julia-1.127.2\scripts\packages\VSCodeServer\src\eval.jl:181
 [17] withpath(f::VSCodeServer.var"#69#74"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String)
    @ VSCodeServer c:\Users\Casper Casier\.vscode\extensions\julialang.language-julia-1.127.2\scripts\packages\VSCodeServer\src\repl.jl:276
 [18] (::VSCodeServer.var"#68#73"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\Casper Casier\.vscode\extensions\julialang.language-julia-1.127.2\scripts\packages\VSCodeServer\src\eval.jl:179
 [19] hideprompt(f::VSCodeServer.var"#68#73"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
    @ VSCodeServer c:\Users\Casper Casier\.vscode\extensions\julialang.language-julia-1.127.2\scripts\packages\VSCodeServer\src\repl.jl:38
 [20] #67
    @ c:\Users\Casper Casier\.vscode\extensions\julialang.language-julia-1.127.2\scripts\packages\VSCodeServer\src\eval.jl:150 [inlined]
 [21] with_logstate(f::VSCodeServer.var"#67#72"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, logstate::Base.CoreLogging.LogState)     
    @ Base.CoreLogging .\logging\logging.jl:522
 [22] with_logger
    @ .\logging\logging.jl:632 [inlined]
 [23] (::VSCodeServer.var"#66#71"{VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\Casper Casier\.vscode\extensions\julialang.language-julia-1.127.2\scripts\packages\VSCodeServer\src\eval.jl:263
 [24] #invokelatest#2
    @ .\essentials.jl:1055 [inlined]
 [25] invokelatest(::Any)
    @ Base .\essentials.jl:1052
 [26] (::VSCodeServer.var"#64#65")()

```

---

<div class="post-metadata">

### Author: ![Casper\_Casier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/casper_casier/32/214252_2.png) [@Casper\_Casier](https://discourse.julialang.org/u/Casper_Casier)
#### Post date: [February 23, 2025, 7:17pm UTC](https://discourse.julialang.org/t/dimensionmismatch-arrays-could-not-be-broadcast-to-a-common-size-a-has-axes-base-oneto-5-and-b-has-axes-base-oneto-0/126193/7 "2025-02-23T19:17:23Z")

</div>

N values shouldn’t matter that much as `true_solutions_noisy` is a dictionary with results for different N values, but I’m only using the results of 1 N value for now. `true_solutions_noisy` contains all concentration profiles over time. For 1 N value, this has a shape of (5,161) like I previously mentioned
