# General Usage

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

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

**Page:** 635

---

## [Improving performance in checking prime numbers](https://discourse.julialang.org/t/improving-performance-in-checking-prime-numbers/56365)

<div class="topic-metadata">

**Author:** [@dariush-bahrami](https://discourse.julialang.org/u/dariush-bahrami)\
**Replies:** 14\
**Last updated:** [March 2, 2021, 10:25pm UTC](https://discourse.julialang.org/t/improving-performance-in-checking-prime-numbers/56365 "2021-03-02T22:25:36Z")

</div>

Hi, I wrote the following code in python with help of numba JIT: from numba import jit @jit(nopython=True) def is\_prime(number): upper\_limit = int(number\*\*0.5) + 1 for i in range(2, upper\_limit): if num…

---

## [Whats a better way to remove elements from an array based on index?\`\`\`g = \[55, 7](https://discourse.julialang.org/t/whats-a-better-way-to-remove-elements-from-an-array-based-on-index-g-55-7/56340)

<div class="topic-metadata">

**Author:** [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Replies:** 9\
**Last updated:** [March 2, 2021, 9:16pm UTC](https://discourse.julialang.org/t/whats-a-better-way-to-remove-elements-from-an-array-based-on-index-g-55-7/56340 "2021-03-02T21:16:00Z")

</div>

whats a better way to remove elements from an array based on index? g = \[55, 77, 88, 99, 3, 7, 8,99,99, 999\] ix\_drop = 2:4 setdiff(g, g\[ix\_drop\]) This works but it will remove duplicate values… and thats less than desi…

---

## [Generic serialization API](https://discourse.julialang.org/t/generic-serialization-api/56366)

<div class="topic-metadata">

**Author:** [@jzr](https://discourse.julialang.org/u/jzr)\
**Replies:** 0\
**Last updated:** [March 2, 2021, 9:14pm UTC](https://discourse.julialang.org/t/generic-serialization-api/56366 "2021-03-02T21:14:43Z")

</div>

Many file format packages have their own serialization and deserialization functions, with different APIs. I would like to have a single unified API. For example, serialize(data::Serializable, target::AbstractTarget,…

---

## [Adding local package results in malformed path (Windows)](https://discourse.julialang.org/t/adding-local-package-results-in-malformed-path-windows/56338)

<div class="topic-metadata">

**Author:** [@eschoute](https://discourse.julialang.org/u/eschoute)\
**Replies:** 2\
**Last updated:** [March 2, 2021, 8:29pm UTC](https://discourse.julialang.org/t/adding-local-package-results-in-malformed-path-windows/56338 "2021-03-02T20:29:51Z")

</div>

On Windows, I think there is a bug with the location of say “Documents” on a different partition. I moved my Documents folder to a different partition. Steps to reproduce: Cd to E:\\Documents Make a package foo (\>\]gene…

---

## [Making Mplay.jl work under Linux](https://discourse.julialang.org/t/making-mplay-jl-work-under-linux/56192)

<div class="topic-metadata">

**Author:** [@tp2750](https://discourse.julialang.org/u/tp2750)\
**Replies:** 5\
**Last updated:** [March 2, 2021, 5:13pm UTC](https://discourse.julialang.org/t/making-mplay-jl-work-under-linux/56192 "2021-03-02T17:13:41Z")

</div>

Here’s how I got Mplay.jl to work under Linux (Ubuntu 20.04). Mplay.jl writes to a “raw midi device”, and Ubuntu does not have those on by default. To create a “virtual midi device” I do $ sudo modprobe snd-virmidi sn…

---

## [How to read Arrow.jl files from R?](https://discourse.julialang.org/t/how-to-read-arrow-jl-files-from-r/56178)

<div class="topic-metadata">

**Author:** [@jzr](https://discourse.julialang.org/u/jzr)\
**Replies:** 7\
**Last updated:** [March 2, 2021, 3:19pm UTC](https://discourse.julialang.org/t/how-to-read-arrow-jl-files-from-r/56178 "2021-03-02T15:19:45Z")

</div>

I used Arrow.write() from Arrow.jl 1.2.4 and read\_feather() from R arrow 3.0.0 but the read said errored: Error in ipc\_\_\_feather\_\_\_Reader\_\_Open(file) : Invalid: Not a Feather V1 or Arrow IPC file How can I read this…

---

## [Define a type alias for an Array of indices that point to the array](https://discourse.julialang.org/t/define-a-type-alias-for-an-array-of-indices-that-point-to-the-array/56333)

<div class="topic-metadata">

**Author:** [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Replies:** 2\
**Last updated:** [March 2, 2021, 1:59pm UTC](https://discourse.julialang.org/t/define-a-type-alias-for-an-array-of-indices-that-point-to-the-array/56333 "2021-03-02T13:59:51Z")

</div>

I want to define a type alias for n-dimensional arrays of n-dimensional cartesian indices (so an array that holds indices that are able to index that array). I tried julia\> MyType = Array{CartesianIndex{N},N} where N a…

---

## [A question about co/countervariance: \`f((x, y)::Tuple{Int, Any}) = 1\`](https://discourse.julialang.org/t/a-question-about-co-countervariance-f-x-y-tuple-int-any-1/56332)

<div class="topic-metadata">

**Author:** [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Replies:** 1\
**Last updated:** [March 2, 2021, 1:27pm UTC](https://discourse.julialang.org/t/a-question-about-co-countervariance-f-x-y-tuple-int-any-1/56332 "2021-03-02T13:27:34Z")

</div>

A question about co/countervariance: julia\> f((x, y)::Tuple{Int, Any}) = 1 f (generic function with 1 method) julia\> f((1,1)) 1 julia\> f((x, y)::Pair{Int, Any}) = 1 f (generic function with 2 methods) julia\> f((1=\>1)…

---

## [Smart RecursiveArrayTools.VectorOfArray which allows binary operations with AbstractVector](https://discourse.julialang.org/t/smart-recursivearraytools-vectorofarray-which-allows-binary-operations-with-abstractvector/56327)

<div class="topic-metadata">

**Author:** [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)\
**Replies:** 1\
**Last updated:** [March 2, 2021, 1:02pm UTC](https://discourse.julialang.org/t/smart-recursivearraytools-vectorofarray-which-allows-binary-operations-with-abstractvector/56327 "2021-03-02T13:02:26Z")

</div>

This is a follow-up question from How to solve set of nonlinear fixed-point equations using Anderson acceleration in NLsolve.jl?. Suppose I have a VectorOfArray object z = VectorOfArray(\[rand(4), rand(4)\]) Then the fol…

---

## [Making code and packages available to workers inside module](https://discourse.julialang.org/t/making-code-and-packages-available-to-workers-inside-module/56311)

<div class="topic-metadata">

**Author:** [@Nikos\_Gianniotis](https://discourse.julialang.org/u/Nikos_Gianniotis)\
**Replies:** 4\
**Last updated:** [March 2, 2021, 11:49am UTC](https://discourse.julialang.org/t/making-code-and-packages-available-to-workers-inside-module/56311 "2021-03-02T11:49:43Z")

</div>

Dear forum, my title explains to some extend what I am trying to achieve. To make it hopefully clearer, I have written the following minimal code as an example. First, I create an ordinary script (scriptA.jl) where the…

---

## [How to stop a thread blocked by readline?](https://discourse.julialang.org/t/how-to-stop-a-thread-blocked-by-readline/56262)

<div class="topic-metadata">

**Author:** [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Replies:** 4\
**Last updated:** [March 2, 2021, 11:37am UTC](https://discourse.julialang.org/t/how-to-stop-a-thread-blocked-by-readline/56262 "2021-03-02T11:37:34Z")

</div>

Hey all :slight\_smile: I want to use a thread redirecting stderr. The thread should stop after a Threads.Atomic is set to false. My current example is blocked on readline and stops only after something is written to it…

---

## [Choosing algorithm for SVD](https://discourse.julialang.org/t/choosing-algorithm-for-svd/56249)

<div class="topic-metadata">

**Author:** [@kadir-gunel](https://discourse.julialang.org/u/kadir-gunel)\
**Replies:** 5\
**Last updated:** [March 2, 2021, 11:07am UTC](https://discourse.julialang.org/t/choosing-algorithm-for-svd/56249 "2021-03-02T11:07:17Z")

</div>

The svd function in LinearAlgebra package has an option to select the algorithm for factorization method. But could not find proper way to use it. using LinearAlgebra A= rand(Float32, 10, 20); F = svd(A, full=true) # wo…

---

## [Including a folder](https://discourse.julialang.org/t/including-a-folder/56308)

<div class="topic-metadata">

**Author:** [@Amval](https://discourse.julialang.org/u/Amval)\
**Replies:** 2\
**Last updated:** [March 2, 2021, 8:51am UTC](https://discourse.julialang.org/t/including-a-folder/56308 "2021-03-02T08:51:51Z")

</div>

Hello, I want to be able to do something like this: module Example include\_folder("my/modules") end And include\_folder should look similar to this: module Utils function include\_folder(path::AbstractString) path…

---

## [Plots not working properly](https://discourse.julialang.org/t/plots-not-working-properly/56310)

<div class="topic-metadata">

**Author:** [@BLI](https://discourse.julialang.org/u/BLI)\
**Replies:** 1\
**Last updated:** [March 2, 2021, 8:39am UTC](https://discourse.julialang.org/t/plots-not-working-properly/56310 "2021-03-02T08:39:49Z")

</div>

I’m on Julia 1.5.0 on my work desktop. Yesterday, I updated the packages (Pkg.update()\] since my 3D scatter-plots didn’t work properly. (pyplot showed the data in the 2D plane, and not in 3D; gr put the axes labels insid…

---

## [Plot multiple lines with different ranges in same plot](https://discourse.julialang.org/t/plot-multiple-lines-with-different-ranges-in-same-plot/56304)

<div class="topic-metadata">

**Author:** [@Hannah\_Rocio\_Santa\_C](https://discourse.julialang.org/u/Hannah_Rocio_Santa_C)\
**Replies:** 4\
**Last updated:** [March 2, 2021, 6:58am UTC](https://discourse.julialang.org/t/plot-multiple-lines-with-different-ranges-in-same-plot/56304 "2021-03-02T06:58:04Z")

</div>

Hello, I would like to plot several lines on a same plot. Each line was created with x in range \[-1,1\] as follows: line\_x\[i\]=-1:0.1:1 line\_y\[i\]=(a\[i\]\* line\_x\[i\] .+ b\[I\]) My problem is that for each line, I would lik…

---

## [Idiomatic Benchmarking](https://discourse.julialang.org/t/idiomatic-benchmarking/56286)

<div class="topic-metadata">

**Author:** [@mileslucas](https://discourse.julialang.org/u/mileslucas)\
**Replies:** 6\
**Last updated:** [March 2, 2021, 6:12am UTC](https://discourse.julialang.org/t/idiomatic-benchmarking/56286 "2021-03-02T06:12:03Z")

</div>

I feel like every time I write a benchmark for a package I’m reinventing the wheel, with slight changes in how I list dependencies, how I organize the actual benchmarks, how I collect results, and how I end up displaying…

---

## [Function inside function is not defined?](https://discourse.julialang.org/t/function-inside-function-is-not-defined/56297)

<div class="topic-metadata">

**Author:** [@amrods](https://discourse.julialang.org/u/amrods)\
**Replies:** 2\
**Last updated:** [March 2, 2021, 3:02am UTC](https://discourse.julialang.org/t/function-inside-function-is-not-defined/56297 "2021-03-02T03:02:21Z")

</div>

I came across this strange behavior: function f(k) if k == 1 g(k) = "k = 1" elseif k == 2 g(k) = "k = 2" end g(k) end f(1) # returns "k = 2" f(2) # errors ERROR: UndefVarError: g not de…

---

## [Fit ODE parameters with different weights for each variable](https://discourse.julialang.org/t/fit-ode-parameters-with-different-weights-for-each-variable/56296)

<div class="topic-metadata">

**Author:** [@Rodrigo\_Zepeda](https://discourse.julialang.org/u/Rodrigo_Zepeda)\
**Replies:** 1\
**Last updated:** [March 2, 2021, 1:09am UTC](https://discourse.julialang.org/t/fit-ode-parameters-with-different-weights-for-each-variable/56296 "2021-03-02T01:09:24Z")

</div>

Hi! I am trying to optimize parameters for an ODE giving different weights to each entry of the solution y inside the L2Loss function. That is all y\[1\]s should have some weights w1 while all y\[3\]s should have some diffe…

---

## [Extracting Ints from a String in a DataFrame](https://discourse.julialang.org/t/extracting-ints-from-a-string-in-a-dataframe/56293)

<div class="topic-metadata">

**Author:** [@statspy](https://discourse.julialang.org/u/statspy)\
**Replies:** 4\
**Last updated:** [March 2, 2021, 12:47am UTC](https://discourse.julialang.org/t/extracting-ints-from-a-string-in-a-dataframe/56293 "2021-03-02T00:47:59Z")

</div>

I have a DataFrame like below: df = DataFrame("Code" =\> \["A03", "W12","C04"\]) The df.Code column is always a 3-character string formed by 1 letter and 2 digits. I need to extract the digits (as int) to a new column le…

---

## [Iterating over a column and changing its value according to a condition](https://discourse.julialang.org/t/iterating-over-a-column-and-changing-its-value-according-to-a-condition/56285)

<div class="topic-metadata">

**Author:** [@statspy](https://discourse.julialang.org/u/statspy)\
**Replies:** 2\
**Last updated:** [March 1, 2021, 10:42pm UTC](https://discourse.julialang.org/t/iterating-over-a-column-and-changing-its-value-according-to-a-condition/56285 "2021-03-01T22:42:20Z")

</div>

I have a .csv file with a column named “Values” ID Values 0 0.201915 1 0.441945 2 0.001931 3 0.221311 4 0.303101 this .csv file has 180900 rows. I need to change the Values according to a condition, l…

---

## [Failed to precompile JellyMe4](https://discourse.julialang.org/t/failed-to-precompile-jellyme4/56287)

<div class="topic-metadata">

**Author:** [@jzr](https://discourse.julialang.org/u/jzr)\
**Replies:** 0\
**Last updated:** [March 1, 2021, 10:27pm UTC](https://discourse.julialang.org/t/failed-to-precompile-jellyme4/56287 "2021-03-01T22:27:04Z")

</div>

What can I do about “Failed to precompile”? using JellyMe4 \[ Info: Precompiling JellyMe4 \[19ac8677-9a15-4623-9afd-84acc6165ce7\] ERROR: Failed to precompile JellyMe4 \[19ac8677-9a15-4623-9afd-84acc6165ce7\] to /home/user/.…

---

## [I made a recursive function to extract a value from a JSON given the key for that](https://discourse.julialang.org/t/i-made-a-recursive-function-to-extract-a-value-from-a-json-given-the-key-for-that/56278)

<div class="topic-metadata">

**Author:** [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Replies:** 1\
**Last updated:** [March 1, 2021, 9:16pm UTC](https://discourse.julialang.org/t/i-made-a-recursive-function-to-extract-a-value-from-a-json-given-the-key-for-that/56278 "2021-03-01T21:16:47Z")

</div>

I made a recursive function to extract a value from a JSON given the key for that value: function extract(json, key) req = \[\] for (k, v) in pairs(json) if k == key println("FOUND $key == $k"…

---

## [Gnuplot.jl outputs debug text for all \`@gp\` commands](https://discourse.julialang.org/t/gnuplot-jl-outputs-debug-text-for-all-gp-commands/56283)

<div class="topic-metadata">

**Author:** [@affans](https://discourse.julialang.org/u/affans)\
**Replies:** 1\
**Last updated:** [March 1, 2021, 8:55pm UTC](https://discourse.julialang.org/t/gnuplot-jl-outputs-debug-text-for-all-gp-commands/56283 "2021-03-01T20:55:23Z")

</div>

I recently upgraded to Julia 1.5 and latest version of Gnuplot. I noticed that gnuplot now has output in the terminal that wasn’t there before. It seems like “errors” but they are not, and the figure is correctly produce…

---

## [Dealing with a bunch of errors](https://discourse.julialang.org/t/dealing-with-a-bunch-of-errors/56276)

<div class="topic-metadata">

**Author:** [@Ross\_Boylan](https://discourse.julialang.org/u/Ross_Boylan)\
**Replies:** 1\
**Last updated:** [March 1, 2021, 8:16pm UTC](https://discourse.julialang.org/t/dealing-with-a-bunch-of-errors/56276 "2021-03-01T20:16:43Z")

</div>

I just got the latest julia and VSCode for Linux and used \] dev to get a bunch of packages to look at. I encountered what seemed like an implausible number of errors, and in some cases errors whose source I am unsure of…

---

## [Multithreading an embarrassingly parallel algorithm increases garbage collection](https://discourse.julialang.org/t/multithreading-an-embarrassingly-parallel-algorithm-increases-garbage-collection/56261)

<div class="topic-metadata">

**Author:** [@andrekal](https://discourse.julialang.org/u/andrekal)\
**Replies:** 12\
**Last updated:** [March 1, 2021, 8:04pm UTC](https://discourse.julialang.org/t/multithreading-an-embarrassingly-parallel-algorithm-increases-garbage-collection/56261 "2021-03-01T20:04:14Z")

</div>

Hi, Hope this MWE is clear enough. I’m trying to implement a certain algorithm in which I fill out a matrix (about 5000x6000) with known dimensions column by column. The calculation of each column is completely indepen…

---

## [StatsBase.summarystats not defined for Rational numbers](https://discourse.julialang.org/t/statsbase-summarystats-not-defined-for-rational-numbers/55165)

<div class="topic-metadata">

**Author:** [@bluesmoon](https://discourse.julialang.org/u/bluesmoon)\
**Replies:** 3\
**Last updated:** [March 1, 2021, 7:11pm UTC](https://discourse.julialang.org/t/statsbase-summarystats-not-defined-for-rational-numbers/55165 "2021-03-01T19:11:29Z")

</div>

Hi, I have code that uses StatsBase.summarystats on a Vector{T} where T \<: Real sometimes T can be Rational, and summarystats fails as it is not defined on Rational. Is there an alternative I can use? My current work…

---

## [Which block \`@inbounds\` actually avoid testing bounds?](https://discourse.julialang.org/t/which-block-inbounds-actually-avoid-testing-bounds/56267)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 3\
**Last updated:** [March 1, 2021, 6:45pm UTC](https://discourse.julialang.org/t/which-block-inbounds-actually-avoid-testing-bounds/56267 "2021-03-01T18:45:31Z")

</div>

For example, this simple function: function f(vec1,vec2) for i in 2:length(vec1) vec1\[i\] = vec1\[i\] - vec2\[i-1\] end nothing end I get: julia\> @btime f($vec1,$vec2) 759.284 ns (0 allocations: 0 bytes) If …

---

## [Inverse transform sampling (discrete distributions sampling)?](https://discourse.julialang.org/t/inverse-transform-sampling-discrete-distributions-sampling/56255)

<div class="topic-metadata">

**Author:** [@riegel\_gestr](https://discourse.julialang.org/u/riegel_gestr)\
**Replies:** 4\
**Last updated:** [March 1, 2021, 6:29pm UTC](https://discourse.julialang.org/t/inverse-transform-sampling-discrete-distributions-sampling/56255 "2021-03-01T18:29:49Z")

</div>

I am currently working on inverse transform sampling: Inverse transform sampling - Wikipedia, also here http://dept.stat.lsa.umich.edu/~jasoneg/Stat406/lab5.pdf I have implemented the following version of the algo: us…

---

## [How do I refer to the directory "one above" the current one?Context: I have a sc](https://discourse.julialang.org/t/how-do-i-refer-to-the-directory-one-above-the-current-one-context-i-have-a-sc/56264)

<div class="topic-metadata">

**Author:** [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Replies:** 1\
**Last updated:** [March 1, 2021, 4:54pm UTC](https://discourse.julialang.org/t/how-do-i-refer-to-the-directory-one-above-the-current-one-context-i-have-a-sc/56264 "2021-03-01T16:54:38Z")

</div>

How do I refer to the directory “one above” the current one? Context: I have a script in /src and have @\_\_DIR\_\_ in that script. But I want to refer to the parent folder, the one containint the Project.toml. joinpath(d, …

---

## [Hi folks. Does anybody know how to parse/convert a String to a Distribution? For e](https://discourse.julialang.org/t/hi-folks-does-anybody-know-how-to-parse-convert-a-string-to-a-distribution-for-e/56257)

<div class="topic-metadata">

**Author:** [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Replies:** 2\
**Last updated:** [March 1, 2021, 4:33pm UTC](https://discourse.julialang.org/t/hi-folks-does-anybody-know-how-to-parse-convert-a-string-to-a-distribution-for-e/56257 "2021-03-01T16:33:05Z")

</div>

Hi folks. Does anybody know how to parse/convert a String to a Distribution? For example “Beta(2,5)” -\> Beta{Float64}(α=2.0, β=5.0). I am trying to store probability distribution values in JSON format and read them into…

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

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