# General Usage

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

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

**Page:** 676

---

## [General advice for how to maximize code performance](https://discourse.julialang.org/t/general-advice-for-how-to-maximize-code-performance/50439)

<div class="topic-metadata">

**Author:** [@fusion809](https://discourse.julialang.org/u/fusion809)\
**Replies:** 1\
**Last updated:** [November 19, 2020, 2:06pm UTC](https://discourse.julialang.org/t/general-advice-for-how-to-maximize-code-performance/50439 "2020-11-19T14:06:25Z")

</div>

I thought I’d ask for what tips you more advanced Julia users have for how to maximize code performance in general. I realize that without a specific use-case some ways may be missed, but I thought I’d check whether yous…

---

## [Zygote is very slow for log barrier function](https://discourse.julialang.org/t/zygote-is-very-slow-for-log-barrier-function/50423)

<div class="topic-metadata">

**Author:** [@minetest2048](https://discourse.julialang.org/u/minetest2048)\
**Replies:** 3\
**Last updated:** [November 19, 2020, 1:59pm UTC](https://discourse.julialang.org/t/zygote-is-very-slow-for-log-barrier-function/50423 "2020-11-19T13:59:26Z")

</div>

I’m trying to implement log barrier function for my gradient descent code: It have an easy derivative (sum of elementwise log → elementwise reciprocal) Here is the script for testing: using Zygote using BenchmarkTo…

---

## [Package(s) for n-body simulations?](https://discourse.julialang.org/t/package-s-for-n-body-simulations/50294)

<div class="topic-metadata">

**Author:** [@oschulz](https://discourse.julialang.org/u/oschulz)\
**Replies:** 4\
**Last updated:** [November 19, 2020, 12:20pm UTC](https://discourse.julialang.org/t/package-s-for-n-body-simulations/50294 "2020-11-19T12:20:33Z")

</div>

What do we currently have in the ecosystem for n-body simulations (with electric-field-like interaction, point-like particles, no collisions)?

---

## [Select multiple columns from pandas dataframe](https://discourse.julialang.org/t/select-multiple-columns-from-pandas-dataframe/50243)

<div class="topic-metadata">

**Author:** [@nadaa](https://discourse.julialang.org/u/nadaa)\
**Replies:** 15\
**Last updated:** [November 19, 2020, 11:30am UTC](https://discourse.julialang.org/t/select-multiple-columns-from-pandas-dataframe/50243 "2020-11-19T11:30:56Z")

</div>

Hi, I imported pandas and read CSV, I can print the data. I want to select the first 3 columns, it is working in Python as df.iloc\[:,:3\] but didn’t work in Julia. I also tried df\[\[“col1”,“col2”,“col3”\]\]. Any suggestion…

---

## [Sample() nchains vs n\_chains](https://discourse.julialang.org/t/sample-nchains-vs-n-chains/50336)

<div class="topic-metadata">

**Author:** [@jzr](https://discourse.julialang.org/u/jzr)\
**Replies:** 2\
**Last updated:** [November 19, 2020, 3:16am UTC](https://discourse.julialang.org/t/sample-nchains-vs-n-chains/50336 "2020-11-19T03:16:46Z")

</div>

sample() has many methods. One has nchains and another has n\_chains. What is the difference between these parameters? nchains: sample(model::AbstractMCMC.AbstractModel, sampler::AbstractMCMC.AbstractSampler, parallel::A…

---

## [Getting model parameter names from DataFrame](https://discourse.julialang.org/t/getting-model-parameter-names-from-dataframe/50008)

<div class="topic-metadata">

**Author:** [@jzr](https://discourse.julialang.org/u/jzr)\
**Replies:** 5\
**Last updated:** [November 19, 2020, 3:15am UTC](https://discourse.julialang.org/t/getting-model-parameter-names-from-dataframe/50008 "2020-11-19T03:15:30Z")

</div>

Suppose I have df = DataFrame( age=\[20, 30, 40\], height=\[80, 130, 200\], ) weight = \[100, 120, 200\] I want to predict weight from the other columns using linear regression. There are two options. Explicitly wr…

---

## [Help using @nloops and @nref](https://discourse.julialang.org/t/help-using-nloops-and-nref/50397)

<div class="topic-metadata">

**Author:** [@gregory](https://discourse.julialang.org/u/gregory)\
**Replies:** 3\
**Last updated:** [November 18, 2020, 11:06pm UTC](https://discourse.julialang.org/t/help-using-nloops-and-nref/50397 "2020-11-18T23:06:48Z")

</div>

Hello, I am trying to build general function that will take the min and max of a K-dimensional array of N data points and use this to create a mesh of a user-specified discretization. For example, here is a 5D array of …

---

## [How to get --machine-file for array tasks?](https://discourse.julialang.org/t/how-to-get-machine-file-for-array-tasks/50401)

<div class="topic-metadata">

**Author:** [@mkarikom](https://discourse.julialang.org/u/mkarikom)\
**Replies:** 0\
**Last updated:** [November 18, 2020, 9:22pm UTC](https://discourse.julialang.org/t/how-to-get-machine-file-for-array-tasks/50401 "2020-11-18T21:22:46Z")

</div>

I have the following sbatch.sub script which defines a job array where each is meant to call run.jl with it’s respective slurm nodefile (please see below). This produces outputs for both array iterations but they say so…

---

## [Same code, very different results with Julia 1.4.2 and Julia 1.5.2](https://discourse.julialang.org/t/same-code-very-different-results-with-julia-1-4-2-and-julia-1-5-2/47416)

<div class="topic-metadata">

**Author:** [@CodeLenz](https://discourse.julialang.org/u/CodeLenz)\
**Replies:** 23\
**Last updated:** [November 18, 2020, 7:02pm UTC](https://discourse.julialang.org/t/same-code-very-different-results-with-julia-1-4-2-and-julia-1-5-2/47416 "2020-11-18T19:02:14Z")

</div>

Hi. I am running a very long piece of code, with finite element, Monte Carlo Simulation (parallel loop) and topology optimization. It turns out that after moving to Julia 1.5.2, I observed a drastic change in all my sol…

---

## [Dynamic dispatch in a for loop](https://discourse.julialang.org/t/dynamic-dispatch-in-a-for-loop/50282)

<div class="topic-metadata">

**Author:** [@drarnau](https://discourse.julialang.org/u/drarnau)\
**Replies:** 17\
**Last updated:** [November 18, 2020, 6:03pm UTC](https://discourse.julialang.org/t/dynamic-dispatch-in-a-for-loop/50282 "2020-11-18T18:03:31Z")

</div>

Hello, While trying to optimise my code, Juno’s profiler flagged a portion of my code as doing some dynamic dispatch. Since my original code is fairly long, here is the smallest example I could come up with to illustrat…

---

## [Testing different constant definitions](https://discourse.julialang.org/t/testing-different-constant-definitions/50376)

<div class="topic-metadata">

**Author:** [@Luapulu](https://discourse.julialang.org/u/Luapulu)\
**Replies:** 5\
**Last updated:** [November 18, 2020, 6:00pm UTC](https://discourse.julialang.org/t/testing-different-constant-definitions/50376 "2020-11-18T18:00:06Z")

</div>

I have a macro, which creates / defines useful constants for the user. I would like to test if the macro created the correct constants and if they function as expected. How can I get something like the following to work? …

---

## [Julia's loop scope behavior differs from Fortran?](https://discourse.julialang.org/t/julias-loop-scope-behavior-differs-from-fortran/50275)

<div class="topic-metadata">

**Author:** [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Replies:** 37\
**Last updated:** [November 18, 2020, 4:52pm UTC](https://discourse.julialang.org/t/julias-loop-scope-behavior-differs-from-fortran/50275 "2020-11-18T16:52:59Z")

</div>

Hi, the oddest thing about Julia is how it behaves in loops (especially For loops). The following example gives me an error, DataVar: Not Defined, and I cannot imagine why: function TestLogic(Nloops) for i in 1:Nlo…

---

## [Examples of memory aliasing](https://discourse.julialang.org/t/examples-of-memory-aliasing/50382)

<div class="topic-metadata">

**Author:** [@wulpuqu](https://discourse.julialang.org/u/wulpuqu)\
**Replies:** 2\
**Last updated:** [November 18, 2020, 3:14pm UTC](https://discourse.julialang.org/t/examples-of-memory-aliasing/50382 "2020-11-18T15:14:35Z")

</div>

Hello, I was reading the definition of AbstractArray in Base and I was searching for concrete cases of memory aliasing with two AbstractArrays. A simple case with SubArrays. julia\> A=randn(10) julia\> Base.mightalias(…

---

## [Plotting GPU data](https://discourse.julialang.org/t/plotting-gpu-data/50379)

<div class="topic-metadata">

**Author:** [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Replies:** 0\
**Last updated:** [November 18, 2020, 12:57pm UTC](https://discourse.julialang.org/t/plotting-gpu-data/50379 "2020-11-18T12:57:52Z")

</div>

Hi, I used to plot 2d arrays directly from the GPU using ArrayFire.jl but it does not work for me anymore: julia\> ArrayFire.image(u0) 0x00007fee23c3f920 no window appears. It could be because I am on OSX but no error …

---

## [Error in ploting a surface with Plots+plotlyjs()](https://discourse.julialang.org/t/error-in-ploting-a-surface-with-plots-plotlyjs/50373)

<div class="topic-metadata">

**Author:** [@tiago](https://discourse.julialang.org/u/tiago)\
**Replies:** 2\
**Last updated:** [November 18, 2020, 12:48pm UTC](https://discourse.julialang.org/t/error-in-ploting-a-surface-with-plots-plotlyjs/50373 "2020-11-18T12:48:40Z")

</div>

Hello, I’m having troubles to plot a surface using the plotlyjs() of the package Plots.jl. Let me show you a simple example of what I’m getting: plotlyjs() x=1:10 y=1:10 z=rand(10,10) plot(x,y,z,st=:surface,fill=true)…

---

## [Julia on Apple M1?](https://discourse.julialang.org/t/julia-on-apple-m1/50366)

<div class="topic-metadata">

**Author:** [@robertfeldt](https://discourse.julialang.org/u/robertfeldt)\
**Replies:** 2\
**Last updated:** [November 18, 2020, 9:32am UTC](https://discourse.julialang.org/t/julia-on-apple-m1/50366 "2020-11-18T09:32:59Z")

</div>

Has anyone tried/managed to compile Julia on one of the new Macs with the ARM Apple M1 CPU? I will get my MacBook in circa 2 weeks and the first thing to get up and running is Julia, if possible. If anyone already has ex…

---

## [How to use a range of DateTime as Dict keys](https://discourse.julialang.org/t/how-to-use-a-range-of-datetime-as-dict-keys/26688)

<div class="topic-metadata">

**Author:** [@farasa](https://discourse.julialang.org/u/farasa)\
**Replies:** 2\
**Last updated:** [November 18, 2020, 9:10am UTC](https://discourse.julialang.org/t/how-to-use-a-range-of-datetime-as-dict-keys/26688 "2020-11-18T09:10:22Z")

</div>

Hello, Is there any way to to do this: P1= DateTime(2015,08,1,12,00,00) P2=DateTime(2015,08,1,20,00,00) range(P1,P2) ==\> 3 . . So then I would like to check time periods if they are between P1 and P2?

---

## [Slurm cpus vs tasks in Distributed](https://discourse.julialang.org/t/slurm-cpus-vs-tasks-in-distributed/50357)

<div class="topic-metadata">

**Author:** [@mkarikom](https://discourse.julialang.org/u/mkarikom)\
**Replies:** 0\
**Last updated:** [November 18, 2020, 5:39am UTC](https://discourse.julialang.org/t/slurm-cpus-vs-tasks-in-distributed/50357 "2020-11-18T05:39:18Z")

</div>

Given that Slurm tasks map to workers in Distributed, it seems like there is actually no representation of Slurm “cpus” in the sbatch “–cpus-per-task” sense. Is this correct?

---

## [Environment variable for julia --procs](https://discourse.julialang.org/t/environment-variable-for-julia-procs/50356)

<div class="topic-metadata">

**Author:** [@jzr](https://discourse.julialang.org/u/jzr)\
**Replies:** 0\
**Last updated:** [November 18, 2020, 5:12am UTC](https://discourse.julialang.org/t/environment-variable-for-julia-procs/50356 "2020-11-18T05:12:16Z")

</div>

For --threads there is JULIA\_NUM\_THREADS. Is there an environment variable for --procs?

---

## [Not show plot in juno ide](https://discourse.julialang.org/t/not-show-plot-in-juno-ide/50354)

<div class="topic-metadata">

**Author:** [@Ravinder\_Ram](https://discourse.julialang.org/u/Ravinder_Ram)\
**Replies:** 0\
**Last updated:** [November 18, 2020, 3:56am UTC](https://discourse.julialang.org/t/not-show-plot-in-juno-ide/50354 "2020-11-18T03:56:31Z")

</div>

when i use gadfly… use plot() nothing is shown in plot tab in juno ide what should i do?

---

## [Specify alternative ffmpeg](https://discourse.julialang.org/t/specify-alternative-ffmpeg/50353)

<div class="topic-metadata">

**Author:** [@jzr](https://discourse.julialang.org/u/jzr)\
**Replies:** 0\
**Last updated:** [November 18, 2020, 3:42am UTC](https://discourse.julialang.org/t/specify-alternative-ffmpeg/50353 "2020-11-18T03:42:49Z")

</div>

FFMPEG.jl uses an included artifact for ffmpeg, but I want to use a different one. How can I specify an alternative ffmpeg?

---

## [When does package code get loaded in a module](https://discourse.julialang.org/t/when-does-package-code-get-loaded-in-a-module/50253)

<div class="topic-metadata">

**Author:** [@louisponet](https://discourse.julialang.org/u/louisponet)\
**Replies:** 16\
**Last updated:** [November 17, 2020, 10:17pm UTC](https://discourse.julialang.org/t/when-does-package-code-get-loaded-in-a-module/50253 "2020-11-17T22:17:54Z")

</div>

Hi all, Since my last question world age problem when does a generated function get generated did not get any answers, maybe because it was too specific, I’ll try again here. I think my issue boils down to this questio…

---

## [Using addprocs and pmap inside a function](https://discourse.julialang.org/t/using-addprocs-and-pmap-inside-a-function/50329)

<div class="topic-metadata">

**Author:** [@sdgu](https://discourse.julialang.org/u/sdgu)\
**Replies:** 0\
**Last updated:** [November 17, 2020, 8:53pm UTC](https://discourse.julialang.org/t/using-addprocs-and-pmap-inside-a-function/50329 "2020-11-17T20:53:07Z")

</div>

Heya, Here’s a code file ex1.jl that does what it’s supposed to when I run julia ex1.jl: module MWE export gen\_complicated\_thing, do\_para function complicated\_helper() return Dict() end function gen\_complicated\_t…

---

## [Interface for subtypes of Core.Real](https://discourse.julialang.org/t/interface-for-subtypes-of-core-real/50299)

<div class="topic-metadata">

**Author:** [@josuagrw](https://discourse.julialang.org/u/josuagrw)\
**Replies:** 6\
**Last updated:** [November 17, 2020, 8:34pm UTC](https://discourse.julialang.org/t/interface-for-subtypes-of-core-real/50299 "2020-11-17T20:34:28Z")

</div>

Many packages subtype Core.Real to take advantage of the generic methods in Base and interface with third-party packages. However, while similar supertypes like Base.Array have their interface defined in the Julia manual…

---

## [Deleting constraints strange behavior](https://discourse.julialang.org/t/deleting-constraints-strange-behavior/50324)

<div class="topic-metadata">

**Author:** [@J\_Friedman](https://discourse.julialang.org/u/J_Friedman)\
**Replies:** 0\
**Last updated:** [November 17, 2020, 7:59pm UTC](https://discourse.julialang.org/t/deleting-constraints-strange-behavior/50324 "2020-11-17T19:59:03Z")

</div>

Why is it that when one deletes an object from a model, it keeps the variable attached? @constraint(model, con, 2x \<= 1) delete(model, con) @constraint(model, con, 2x \<= 1) ERROR: An object of name con is already att…

---

## [Matrix multiplication](https://discourse.julialang.org/t/matrix-multiplication/50293)

<div class="topic-metadata">

**Author:** [@nhavt](https://discourse.julialang.org/u/nhavt)\
**Replies:** 6\
**Last updated:** [November 17, 2020, 7:45pm UTC](https://discourse.julialang.org/t/matrix-multiplication/50293 "2020-11-17T19:45:22Z")

</div>

Hi there, I need to perform many matrix multiplications as follows. Here I proposed two functions (f1 and f2). I am wondering whether we could improve the speed of the function f2 further? Thanks in advance! using Line…

---

## [Variable which disappear in a for](https://discourse.julialang.org/t/variable-which-disappear-in-a-for/50304)

<div class="topic-metadata">

**Author:** [@Dailysight](https://discourse.julialang.org/u/Dailysight)\
**Replies:** 6\
**Last updated:** [November 17, 2020, 7:32pm UTC](https://discourse.julialang.org/t/variable-which-disappear-in-a-for/50304 "2020-11-17T19:32:17Z")

</div>

Hey everyone ! First of all, i would like to thank everyone of this community for the help you give to beginners like me. Actually, i have a problem about a variable which disappear when i enter a for loop. Does anyon…

---

## [Parallel programing with Distributed Arrays](https://discourse.julialang.org/t/parallel-programing-with-distributed-arrays/50305)

<div class="topic-metadata">

**Author:** [@hyacykcharel](https://discourse.julialang.org/u/hyacykcharel)\
**Replies:** 0\
**Last updated:** [November 17, 2020, 3:59pm UTC](https://discourse.julialang.org/t/parallel-programing-with-distributed-arrays/50305 "2020-11-17T15:59:12Z")

</div>

Hello, I’m trying to run this code, but why I’m I getting these 2 rows in the Middle with 00000, can someone help me, to get that fixed, please? using Distributed #Bereitstellung der Bibliothekee zur Parallelen Programi…

---

## [Is it necessary to use "global" with try/catch inside a function?](https://discourse.julialang.org/t/is-it-necessary-to-use-global-with-try-catch-inside-a-function/50300)

<div class="topic-metadata">

**Author:** [@Jacob\_Stevens](https://discourse.julialang.org/u/Jacob_Stevens)\
**Replies:** 2\
**Last updated:** [November 17, 2020, 1:44pm UTC](https://discourse.julialang.org/t/is-it-necessary-to-use-global-with-try-catch-inside-a-function/50300 "2020-11-17T13:44:36Z")

</div>

I’m running a simple find\_zero(), and to help me identify errors the core of the function being solved is inside a try/catch circuit: function getA(input) # then main simulation println("Running 1982 onwa…

---

## [Is there a continuous range type in julia?](https://discourse.julialang.org/t/is-there-a-continuous-range-type-in-julia/50298)

<div class="topic-metadata">

**Author:** [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)\
**Replies:** 2\
**Last updated:** [November 17, 2020, 1:29pm UTC](https://discourse.julialang.org/t/is-there-a-continuous-range-type-in-julia/50298 "2020-11-17T13:29:49Z")

</div>

Hi, I was wondering if there exists a continuous range type. The idea would be to be able to have something like 0.5 in CRange(0,1) to return true. The interest is mostly syntactic I guess, but since continuous ranges…

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

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