# General Usage

**URL:** https://discourse.julialang.org/c/usage/6.md?page=591

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

**Page:** 592

---

## [Obtain cartesian indices from dimensions only](https://discourse.julialang.org/t/obtain-cartesian-indices-from-dimensions-only/62366)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 4\
**Last updated:** [June 4, 2021, 12:03am UTC](https://discourse.julialang.org/t/obtain-cartesian-indices-from-dimensions-only/62366 "2021-06-04T00:03:36Z")

</div>

I can obtain the cartesian indices of a matrix from a linear index with: julia\> A = zeros(2,4,3); julia\> CartesianIndices(A)\[5\] CartesianIndex(1, 3, 1) I would want to obtain that without having to define A, that is,…

---

## [Minimize Allocations](https://discourse.julialang.org/t/minimize-allocations/62362)

<div class="topic-metadata">

**Author:** [@natgeo-wong](https://discourse.julialang.org/u/natgeo-wong)\
**Replies:** 3\
**Last updated:** [June 3, 2021, 11:04pm UTC](https://discourse.julialang.org/t/minimize-allocations/62362 "2021-06-03T23:04:01Z")

</div>

Hi! How do I minimize allocations here? I thought that since all variables involved here are scalars, there should be minimal allocations? function ϕfield!( ϕn::Array{FT}, ϕ::Array{FT}, u::Array{FT}, v::Array{FT},…

---

## [MKL threading bug?](https://discourse.julialang.org/t/mkl-threading-bug/62342)

<div class="topic-metadata">

**Author:** [@juthohaegeman](https://discourse.julialang.org/u/juthohaegeman)\
**Replies:** 4\
**Last updated:** [June 3, 2021, 9:21pm UTC](https://discourse.julialang.org/t/mkl-threading-bug/62342 "2021-06-03T21:21:56Z")

</div>

Before posting this as a github issue, I wanted to confirm that this is not some problem with my computer. The following happens for me, but only on mac (macOs Mojave 10.14.6, MacBook Pro (15-inch, 2016), 2,9 GHz Intel …

---

## [How to speed up permutedims for high dimensional tensors](https://discourse.julialang.org/t/how-to-speed-up-permutedims-for-high-dimensional-tensors/62351)

<div class="topic-metadata">

**Author:** [@1115](https://discourse.julialang.org/u/1115)\
**Replies:** 3\
**Last updated:** [June 3, 2021, 8:58pm UTC](https://discourse.julialang.org/t/how-to-speed-up-permutedims-for-high-dimensional-tensors/62351 "2021-06-03T20:58:51Z")

</div>

I find permutedims is so slow, this is something can not be explained by complexity theory. It is because the permutedims is not fully optimized? it occupies \>90% of the computing time of my tensor program. julia\> a = …

---

## [Generating random functions (as opposed to random numbers)](https://discourse.julialang.org/t/generating-random-functions-as-opposed-to-random-numbers/62328)

<div class="topic-metadata">

**Author:** [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Replies:** 14\
**Last updated:** [June 3, 2021, 2:53pm UTC](https://discourse.julialang.org/t/generating-random-functions-as-opposed-to-random-numbers/62328 "2021-06-03T14:53:23Z")

</div>

I need to write a single-argument function f(r::Number) that returns a different random number for different values of r, but always the same number for the same r. Same r is meant in the sense of isequal or ==, it doesn…

---

## [Closure in struct type inference](https://discourse.julialang.org/t/closure-in-struct-type-inference/62180)

<div class="topic-metadata">

**Author:** [@cdawg](https://discourse.julialang.org/u/cdawg)\
**Replies:** 12\
**Last updated:** [June 3, 2021, 1:57pm UTC](https://discourse.julialang.org/t/closure-in-struct-type-inference/62180 "2021-06-03T13:57:10Z")

</div>

This comes up a lot in my code style. I’ve been doing this thing which is to store methods inside a struct as closures. (sort of like oo programming I guess?). This is a lot more convenient than storing the captured valu…

---

## [Param fit for ODE, starting from 0 or restarting from intermediate time points give different results](https://discourse.julialang.org/t/param-fit-for-ode-starting-from-0-or-restarting-from-intermediate-time-points-give-different-results/61781)

<div class="topic-metadata">

**Author:** [@cricci](https://discourse.julialang.org/u/cricci)\
**Replies:** 4\
**Last updated:** [June 3, 2021, 10:39am UTC](https://discourse.julialang.org/t/param-fit-for-ode-starting-from-0-or-restarting-from-intermediate-time-points-give-different-results/61781 "2021-06-03T10:39:57Z")

</div>

My problem is the following. I have an ODE with some parameters to estimate, based on some data. In this example however I will generate the data from the ode itself to make some test. I take an example from LotkaVolter…

---

## [Plots.jl tiny plots in Jupyter](https://discourse.julialang.org/t/plots-jl-tiny-plots-in-jupyter/62281)

<div class="topic-metadata">

**Author:** [@Henri\_Laurie](https://discourse.julialang.org/u/Henri_Laurie)\
**Replies:** 6\
**Last updated:** [June 3, 2021, 9:10am UTC](https://discourse.julialang.org/t/plots-jl-tiny-plots-in-jupyter/62281 "2021-06-03T09:10:30Z")

</div>

Sadly, this is still a problem. The workaround still fixes it. Also the PyPlot backend doesn’t show this, weirdly enough. Looks like I’m stuck with pyplot() for the introductory course I will teach in 6 weeks time. I on…

---

## [Reading and interpreting math in text file](https://discourse.julialang.org/t/reading-and-interpreting-math-in-text-file/62320)

<div class="topic-metadata">

**Author:** [@Marc\_Sevaux](https://discourse.julialang.org/u/Marc_Sevaux)\
**Replies:** 3\
**Last updated:** [June 3, 2021, 8:44am UTC](https://discourse.julialang.org/t/reading-and-interpreting-math-in-text-file/62320 "2021-06-03T08:44:37Z")

</div>

Hi all, I have a text file containing data like : 2.2\*cos(pi\*25/16), 2.2\*sin(pi\*25/16) 2.2\*cos(pi\*23/16), 2.2\*sin(pi\*23/16) 2.2\*cos(pi\*7/16) , 2.2\*sin(pi\*7/16) ... I would like to read these data and store them as num…

---

## [LinearAlgebra.SingularException(2) when solving matrix equation which is solvable in Maple](https://discourse.julialang.org/t/linearalgebra-singularexception-2-when-solving-matrix-equation-which-is-solvable-in-maple/62142)

<div class="topic-metadata">

**Author:** [@vikhes](https://discourse.julialang.org/u/vikhes)\
**Replies:** 7\
**Last updated:** [June 3, 2021, 7:24am UTC](https://discourse.julialang.org/t/linearalgebra-singularexception-2-when-solving-matrix-equation-which-is-solvable-in-maple/62142 "2021-06-03T07:24:23Z")

</div>

Hi I’m doing an assignment where I use my own implementation of Implicit Eulers with adaptive step size using error estimation. For this, I have made my own implementation of the Newton solver. In one ODE system, my num…

---

## [Prose comment in plot](https://discourse.julialang.org/t/prose-comment-in-plot/62309)

<div class="topic-metadata">

**Author:** [@jzr](https://discourse.julialang.org/u/jzr)\
**Replies:** 3\
**Last updated:** [June 3, 2021, 6:04am UTC](https://discourse.julialang.org/t/prose-comment-in-plot/62309 "2021-06-03T06:04:39Z")

</div>

I want to put a comment in my plot. How can I format it as a normal paragraph, with each line pressed against the left edge? using CairoMakie using TextWrap fig = Figure() fig\[1:2, 1:3\] = \[Axis(fig) for \_ in 1:6\] supe…

---

## [Obtain multiple components from a ComponentArray](https://discourse.julialang.org/t/obtain-multiple-components-from-a-componentarray/62315)

<div class="topic-metadata">

**Author:** [@amrods](https://discourse.julialang.org/u/amrods)\
**Replies:** 2\
**Last updated:** [June 3, 2021, 3:58am UTC](https://discourse.julialang.org/t/obtain-multiple-components-from-a-componentarray/62315 "2021-06-03T03:58:22Z")

</div>

Is there a way to obtain multiple components from a ComponentArray? something like using ComponentArrays ca = ComponentArray(x1 = \[1, 2\], x2 = \[10, 20\], x3 = \[100, 200\]) ca\[:x1, :x3\] # would return (ca.x1, ca.x2)

---

## [Flux or Knet?](https://discourse.julialang.org/t/flux-or-knet/45803)

<div class="topic-metadata">

**Author:** [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)\
**Replies:** 7\
**Last updated:** [June 3, 2021, 1:35am UTC](https://discourse.julialang.org/t/flux-or-knet/45803 "2021-06-03T01:35:21Z")

</div>

I need to apply some machine learning algorithms to a very big dataset (about 30 G). I personally prefer pure Julia implementations without any dependencies on Python. Here are my lists of algorithms and corresponding Py…

---

## [How to get axes from figure?](https://discourse.julialang.org/t/how-to-get-axes-from-figure/62307)

<div class="topic-metadata">

**Author:** [@jzr](https://discourse.julialang.org/u/jzr)\
**Replies:** 1\
**Last updated:** [June 2, 2021, 11:15pm UTC](https://discourse.julialang.org/t/how-to-get-axes-from-figure/62307 "2021-06-02T23:15:25Z")

</div>

I have a figure whose layout is \> fig.layout GridLayout\[4, 1\] with 4 children ┣━ \[1, 1\] Axis ┣━ \[2, 1\] Axis ┣━ \[3, 1\] Axis ┗━ \[4, 1\] Axis How can I get the axes from that?

---

## [Adding Labels to Inset/Lens Plots](https://discourse.julialang.org/t/adding-labels-to-inset-lens-plots/62304)

<div class="topic-metadata">

**Author:** [@arnab](https://discourse.julialang.org/u/arnab)\
**Replies:** 1\
**Last updated:** [June 2, 2021, 11:12pm UTC](https://discourse.julialang.org/t/adding-labels-to-inset-lens-plots/62304 "2021-06-02T23:12:27Z")

</div>

I am trying to use lens! to zoom in on part of a plot following this tutorial. However, I want to add a separate label to the inset plot. Is there an easy way to do this in Julia? Thanks!

---

## [Error with \`show\` for abbreviated type printing](https://discourse.julialang.org/t/error-with-show-for-abbreviated-type-printing/62190)

<div class="topic-metadata">

**Author:** [@jonniedie](https://discourse.julialang.org/u/jonniedie)\
**Replies:** 8\
**Last updated:** [June 2, 2021, 11:05pm UTC](https://discourse.julialang.org/t/error-with-show-for-abbreviated-type-printing/62190 "2021-06-02T23:05:09Z")

</div>

Let’s say I have a type with an abbreviated show method for the type itself (for shortened stacktraces). struct Blarg{X,Y} x::X y::Y end Base.show(io::IO, ::Type{Blarg{X,Y}}) where {X,Y} = print(io, "Blarg{$X,.…

---

## [Why does the hash() method produce the same hash after a field value changes?](https://discourse.julialang.org/t/why-does-the-hash-method-produce-the-same-hash-after-a-field-value-changes/62286)

<div class="topic-metadata">

**Author:** [@anon60034542](https://discourse.julialang.org/u/anon60034542)\
**Replies:** 9\
**Last updated:** [June 2, 2021, 10:04pm UTC](https://discourse.julialang.org/t/why-does-the-hash-method-produce-the-same-hash-after-a-field-value-changes/62286 "2021-06-02T22:04:47Z")

</div>

Consider the following code: mutable struct Person name::String age::Int32 end svetlana = Person("Queen Svetlana",25) println(hash(svetlana)) # 1143118284 svetlana.age = 30 println(hash(svetlana)) # 1143118284…

---

## [Permissions for installing packages on julia in slurm cluster](https://discourse.julialang.org/t/permissions-for-installing-packages-on-julia-in-slurm-cluster/62246)

<div class="topic-metadata">

**Author:** [@JDA](https://discourse.julialang.org/u/JDA)\
**Replies:** 13\
**Last updated:** [June 2, 2021, 8:25pm UTC](https://discourse.julialang.org/t/permissions-for-installing-packages-on-julia-in-slurm-cluster/62246 "2021-06-02T20:25:40Z")

</div>

Hello, I am having some issues with permissions getting julia started on a slurm cluster. I could use some assistance, if possible. The issue is explained here https://stackoverflow.com/questions/67794194/permissions-…

---

## [Libraries for Computational Graphs](https://discourse.julialang.org/t/libraries-for-computational-graphs/62293)

<div class="topic-metadata">

**Author:** [@Satvik](https://discourse.julialang.org/u/Satvik)\
**Replies:** 2\
**Last updated:** [June 2, 2021, 7:16pm UTC](https://discourse.julialang.org/t/libraries-for-computational-graphs/62293 "2021-06-02T19:16:38Z")

</div>

Hi, I have functions that look something like this: C(x) = A(x) + B(x) B(x) = 2\*A(x) A(x) = exp(x) where I’d like to calculate C(x) while only evaluating A(x) once. The actual situation is more complex, e.g. a naive i…

---

## [Makie: Combine plots into subplots](https://discourse.julialang.org/t/makie-combine-plots-into-subplots/62280)

<div class="topic-metadata">

**Author:** [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Replies:** 4\
**Last updated:** [June 2, 2021, 6:51pm UTC](https://discourse.julialang.org/t/makie-combine-plots-into-subplots/62280 "2021-06-02T18:51:31Z")

</div>

In Plots.jl, I can make a plot and then use it either as a stand-alone figure or as a subplot: using Plots myplot(n) = plot(1 : n; xlabel = "x") f1 = myplot(10); f2 = myplot(20); fig = plot(f1, f2); Can I do somethin…

---

## [Problem with @avx and LoopVectorization: UndefVarError](https://discourse.julialang.org/t/problem-with-avx-and-loopvectorization-undefvarerror/62279)

<div class="topic-metadata">

**Author:** [@jmcastro2109](https://discourse.julialang.org/u/jmcastro2109)\
**Replies:** 3\
**Last updated:** [June 2, 2021, 5:13pm UTC](https://discourse.julialang.org/t/problem-with-avx-and-loopvectorization-undefvarerror/62279 "2021-06-02T17:13:17Z")

</div>

Hello, I am running the following code using LoopVectorization, using Random, BenchmarkTools, LoopVectorization J = 1000 T = 100 Mat1 = rand(J,J) vec1 = rand(J) Mat2= rand(J,J) vec2 = rand(J) Mat3 = rand(J,J,T) ve…

---

## [Print elements of vector without the braces](https://discourse.julialang.org/t/print-elements-of-vector-without-the-braces/62269)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 1\
**Last updated:** [June 2, 2021, 12:16pm UTC](https://discourse.julialang.org/t/print-elements-of-vector-without-the-braces/62269 "2021-06-02T12:16:38Z")

</div>

Many times I want to output a simple data table from a vector, like in this MWE: julia\> for i in 1:5 println(rand(3)) end \[0.6125928743733668, 0.36073254544716105, 0.5008360754548771\] \[0.0429530986755386…

---

## [Plots.jl tiny plots in jupyter-notebook](https://discourse.julialang.org/t/plots-jl-tiny-plots-in-jupyter-notebook/14770)

<div class="topic-metadata">

**Author:** [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Replies:** 10\
**Last updated:** [September 23, 2018, 4:49am UTC](https://discourse.julialang.org/t/plots-jl-tiny-plots-in-jupyter-notebook/14770 "2018-09-23T04:49:58Z")

</div>

Pkg upgraded my packages and now all jupyter-notbook plots are tiny. Any idea how to fix this?

---

## [Are BigFloats unable to exactly represent 0.1?](https://discourse.julialang.org/t/are-bigfloats-unable-to-exactly-represent-0-1/62192)

<div class="topic-metadata">

**Author:** [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Replies:** 12\
**Last updated:** [June 2, 2021, 11:05am UTC](https://discourse.julialang.org/t/are-bigfloats-unable-to-exactly-represent-0-1/62192 "2021-06-02T11:05:34Z")

</div>

0.1 is a number that can be exactly represented by a Float16, or Float32, or a Float64. (at least according to how we print them) But not it would seem (at least according to printing) by a BigFloat. julia\> parse(Floa…

---

## [Assert relationship between variables with Symbolics.jl](https://discourse.julialang.org/t/assert-relationship-between-variables-with-symbolics-jl/62204)

<div class="topic-metadata">

**Author:** [@EvoArt](https://discourse.julialang.org/u/EvoArt)\
**Replies:** 1\
**Last updated:** [June 2, 2021, 10:09am UTC](https://discourse.julialang.org/t/assert-relationship-between-variables-with-symbolics-jl/62204 "2021-06-02T10:09:02Z")

</div>

Hi I was just wondering if there’s a way to assert and then test for a relationship between two varablie in Symbolics, or Julia in general. Specifically, a game theory payoff table | | R | W |R| 0 | b |W| b-k…

---

## [Parallelizing a for-loop with a matrix](https://discourse.julialang.org/t/parallelizing-a-for-loop-with-a-matrix/62250)

<div class="topic-metadata">

**Author:** [@natgeo-wong](https://discourse.julialang.org/u/natgeo-wong)\
**Replies:** 2\
**Last updated:** [June 2, 2021, 7:00am UTC](https://discourse.julialang.org/t/parallelizing-a-for-loop-with-a-matrix/62250 "2021-06-02T07:00:50Z")

</div>

I have a simple for-loop with a matrix, where I calculate a slice of the matrix via each step of the for-loop. e.g. for ilat = 1 : nlat, ilon = 1 : nlon for ip = 1 : np; esat\[ip+1\] = t2esat(Ta\[ilon,ilat,ip\],p\[ip+1…

---

## [Switch off chunks of code](https://discourse.julialang.org/t/switch-off-chunks-of-code/62247)

<div class="topic-metadata">

**Author:** [@Adriel](https://discourse.julialang.org/u/Adriel)\
**Replies:** 3\
**Last updated:** [June 2, 2021, 5:02am UTC](https://discourse.julialang.org/t/switch-off-chunks-of-code/62247 "2021-06-02T05:02:33Z")

</div>

I’m wondering if there’s a way to completely remove sections of debug/analytics code via some switch, similar to #define in C. Currently I’m just doing this. function f(x, analyse=false) # compute output if anal…

---

## [Adding to a Makie.meshscatter plot](https://discourse.julialang.org/t/adding-to-a-makie-meshscatter-plot/62154)

<div class="topic-metadata">

**Author:** [@baptnz](https://discourse.julialang.org/u/baptnz)\
**Replies:** 4\
**Last updated:** [June 2, 2021, 3:45am UTC](https://discourse.julialang.org/t/adding-to-a-makie-meshscatter-plot/62154 "2021-06-02T03:45:51Z")

</div>

I’m not finding the right argument/function to add a new meshscatter to an existing “scene” (if that’s still the name). using Makie xs = cos.(1:0.5:20) ys = sin.(1:0.5:20) zs = LinRange(0, 3, length(xs)) meshscatter(x…

---

## [Can I detect if code is being run from a generated function?](https://discourse.julialang.org/t/can-i-detect-if-code-is-being-run-from-a-generated-function/62241)

<div class="topic-metadata">

**Author:** [@marius311](https://discourse.julialang.org/u/marius311)\
**Replies:** 3\
**Last updated:** [June 2, 2021, 2:33am UTC](https://discourse.julialang.org/t/can-i-detect-if-code-is-being-run-from-a-generated-function/62241 "2021-06-02T02:33:48Z")

</div>

Is there any way to detect if some code is being run inside a generated function? Something like: function foo() if being\_called\_from\_a\_generated\_function() # do something else # do it slightly d…

---

## [How to update packages and create a system image](https://discourse.julialang.org/t/how-to-update-packages-and-create-a-system-image/62229)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 1\
**Last updated:** [June 1, 2021, 11:48pm UTC](https://discourse.julialang.org/t/how-to-update-packages-and-create-a-system-image/62229 "2021-06-01T23:48:12Z")

</div>

Hello, I am using a bash script to create a new system image when the source code, in particular the set of used packages of my project has changed (after git pull). The core are the following three lines: rm -f Manif…

[Previous page](https://discourse.julialang.org/c/usage/6.md?page=590)

[Next page](https://discourse.julialang.org/c/usage/6.md?page=592)
