# General Usage

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

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

**Page:** 548

---

## [Convert 1D Array to 1D Array of StaticArrays?](https://discourse.julialang.org/t/convert-1d-array-to-1d-array-of-staticarrays/67657)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 11\
**Last updated:** [September 13, 2021, 12:10pm UTC](https://discourse.julialang.org/t/convert-1d-array-to-1d-array-of-staticarrays/67657 "2021-09-13T12:10:36Z")

</div>

Hello! I think this should be fairly simple, suppose I have: b = collect(1:999) Where x,y, and z are given as: x = b\[1:3:end\] y = b\[2:3:end\] z = b\[3:3:end\] How would I then convert / parse this into a Vector of Stat…

---

## [Julia is Overwriting output of a Function](https://discourse.julialang.org/t/julia-is-overwriting-output-of-a-function/68061)

<div class="topic-metadata">

**Author:** [@jmcastro2109](https://discourse.julialang.org/u/jmcastro2109)\
**Replies:** 2\
**Last updated:** [September 13, 2021, 5:13am UTC](https://discourse.julialang.org/t/julia-is-overwriting-output-of-a-function/68061 "2021-09-13T05:13:09Z")

</div>

Hello, I am having a very weird behavior in Julia, however, I am having a hard time reproducing it in a MWE. Let me try to describe it, with an example which does not reproduce the error function test(x,y) res…

---

## [Fastest way to swap bytes order in-place (ntoh)](https://discourse.julialang.org/t/fastest-way-to-swap-bytes-order-in-place-ntoh/68053)

<div class="topic-metadata">

**Author:** [@jling](https://discourse.julialang.org/u/jling)\
**Replies:** 1\
**Last updated:** [September 13, 2021, 12:56am UTC](https://discourse.julialang.org/t/fastest-way-to-swap-bytes-order-in-place-ntoh/68053 "2021-09-13T00:56:47Z")

</div>

Originally we had real\_data = ntoh.(reinterpret(T, rawdata)) where T is some element type such as Float64, rawdata is always a UIn8 vector. After some help from Slack, we’ve moved to: real\_data = GC.@preserve rawdata…

---

## [Type hierarchy of reinterpreted arrays](https://discourse.julialang.org/t/type-hierarchy-of-reinterpreted-arrays/68066)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 0\
**Last updated:** [September 12, 2021, 11:42pm UTC](https://discourse.julialang.org/t/type-hierarchy-of-reinterpreted-arrays/68066 "2021-09-12T23:42:22Z")

</div>

Is it correct to say that a reinterpreted array belongs to the same place in the type hierarchy of the original array? Meaning: julia\> x = rand(3,3) 3×3 Matrix{Float64}: 0.147486 0.663168 0.631236 0.133914 0.63211…

---

## [Running an external program with non-zero return values](https://discourse.julialang.org/t/running-an-external-program-with-non-zero-return-values/68057)

<div class="topic-metadata">

**Author:** [@pfarndt](https://discourse.julialang.org/u/pfarndt)\
**Replies:** 2\
**Last updated:** [September 12, 2021, 10:20pm UTC](https://discourse.julialang.org/t/running-an-external-program-with-non-zero-return-values/68057 "2021-09-12T22:20:52Z")

</div>

I want to parse a diff from two versions of a file. Thought to do this by running diff as an external program and reading its output into a String: read(\`diff version1.txt version2.txt\`, String) This works fine and ret…

---

## [Help defining setindex! with a custom structure](https://discourse.julialang.org/t/help-defining-setindex-with-a-custom-structure/68055)

<div class="topic-metadata">

**Author:** [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Replies:** 9\
**Last updated:** [September 12, 2021, 5:57pm UTC](https://discourse.julialang.org/t/help-defining-setindex-with-a-custom-structure/68055 "2021-09-12T17:57:29Z")

</div>

Hi! I have a struct called Quaternion (which has 4 elements) and I want to make the following code work: julia\> v = zeros(10); julia\> q = Quaternion(1.0, 2.0, 3.0, 4.0); julia\> v\[4:7\] = q It fails with the following…

---

## [Fastest way to permute Array, given some permutation](https://discourse.julialang.org/t/fastest-way-to-permute-array-given-some-permutation/49687)

<div class="topic-metadata">

**Author:** [@DavidBerghaus](https://discourse.julialang.org/u/DavidBerghaus)\
**Replies:** 13\
**Last updated:** [September 12, 2021, 1:06pm UTC](https://discourse.julialang.org/t/fastest-way-to-permute-array-given-some-permutation/49687 "2021-09-12T13:06:19Z")

</div>

I wonder what the fastest way is to apply a permutation to an array. Three approaches that I checked are: julia\> A = rand(10000); julia\> permutation = sortperm(A); julia\> @btime $A\[$permutation\]; 11.700 μs (3 alloca…

---

## [How to call an imported (predefined) macro as a function on expressions?](https://discourse.julialang.org/t/how-to-call-an-imported-predefined-macro-as-a-function-on-expressions/68015)

<div class="topic-metadata">

**Author:** [@thisismygitrepo](https://discourse.julialang.org/u/thisismygitrepo)\
**Replies:** 6\
**Last updated:** [September 12, 2021, 12:52pm UTC](https://discourse.julialang.org/t/how-to-call-an-imported-predefined-macro-as-a-function-on-expressions/68015 "2021-09-12T12:52:16Z")

</div>

Say that I installed a package that provides the macro @pipe, and I am making my own macro that uses that one. My question is, how can I call that macro as a function. somehow / ideally: modified\_expression = pipe(expre…

---

## [Change width of cell and table of contents in Pluto](https://discourse.julialang.org/t/change-width-of-cell-and-table-of-contents-in-pluto/68047)

<div class="topic-metadata">

**Author:** [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Replies:** 0\
**Last updated:** [September 12, 2021, 10:57am UTC](https://discourse.julialang.org/t/change-width-of-cell-and-table-of-contents-in-pluto/68047 "2021-09-12T10:57:02Z")

</div>

I would like to expand the width of cells in Pluto and modify the width of the table of contents to prevent it from displaying on top of the cells. How can this be done?

---

## [Transfer a Sparse Matrix to a C Function](https://discourse.julialang.org/t/transfer-a-sparse-matrix-to-a-c-function/67883)

<div class="topic-metadata">

**Author:** [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)\
**Replies:** 13\
**Last updated:** [September 11, 2021, 7:48pm UTC](https://discourse.julialang.org/t/transfer-a-sparse-matrix-to-a-c-function/67883 "2021-09-11T19:48:26Z")

</div>

I have a C function (See IncompleteCholeskyDecomposition.c) which accepts a Sparse Matrix in CSC format (Actually 2 matrices). I wonder, how do I extract the data, row index and column pointer from a given Julia Sparse …

---

## [Symbolics.jl & @syms?](https://discourse.julialang.org/t/symbolics-jl-syms/67994)

<div class="topic-metadata">

**Author:** [@BLI](https://discourse.julialang.org/u/BLI)\
**Replies:** 3\
**Last updated:** [September 11, 2021, 8:34pm UTC](https://discourse.julialang.org/t/symbolics-jl-syms/67994 "2021-09-11T20:34:48Z")

</div>

Just curious… I noticed that the SymbolicUtils.jl documentation (now) uses @syms to create new symbolic variables. The same seems to work in Symbolics.jl and ModelingToolkit.jl. Is this a change from using @variables, o…

---

## [Can I get this syntax to work using zip?](https://discourse.julialang.org/t/can-i-get-this-syntax-to-work-using-zip/68009)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 14\
**Last updated:** [September 11, 2021, 5:27pm UTC](https://discourse.julialang.org/t/can-i-get-this-syntax-to-work-using-zip/68009 "2021-09-11T17:27:24Z")

</div>

Hello! Suppose I have two points defined as: p1 = (1.0,1.0) p2 = (1.0,1.025) Then I want to calculate the pair-wise distance between the two as such: for (i,j) in zip(p1,p2) diff = i - j end And I want the outpu…

---

## [Writing Data to JSON Files on HPC Cluster](https://discourse.julialang.org/t/writing-data-to-json-files-on-hpc-cluster/67943)

<div class="topic-metadata">

**Author:** [@Noah\_Guzman](https://discourse.julialang.org/u/Noah_Guzman)\
**Replies:** 4\
**Last updated:** [September 11, 2021, 4:53pm UTC](https://discourse.julialang.org/t/writing-data-to-json-files-on-hpc-cluster/67943 "2021-09-11T16:53:54Z")

</div>

Having some issues saving the output of Julia simulations (stochastic differential equations) in a SLURM cluster to JSON files. The cluster manager and I have not been able to figure this out. My original program runs ma…

---

## [Best way to store subsets of a sample](https://discourse.julialang.org/t/best-way-to-store-subsets-of-a-sample/68018)

<div class="topic-metadata">

**Author:** [@tlorans](https://discourse.julialang.org/u/tlorans)\
**Replies:** 6\
**Last updated:** [September 11, 2021, 11:44am UTC](https://discourse.julialang.org/t/best-way-to-store-subsets-of-a-sample/68018 "2021-09-11T11:44:19Z")

</div>

Hello everyone, I would like to store subsamples from an initial sample of data, perform different operations according to the subsample, and then return outputs in the same order than the initial inputs (\*\* EDIT: with …

---

## [LinearInterpolation between two points](https://discourse.julialang.org/t/linearinterpolation-between-two-points/67090)

<div class="topic-metadata">

**Author:** [@ymtoo](https://discourse.julialang.org/u/ymtoo)\
**Replies:** 5\
**Last updated:** [September 11, 2021, 10:22am UTC](https://discourse.julialang.org/t/linearinterpolation-between-two-points/67090 "2021-09-11T10:22:34Z")

</div>

MWE: using Interpolations itp1 = LinearInterpolation(\[1,8600\],\[1,8600\]; extrapolation\_bc=Line()) convert(Float64, itp1(8700)) #-1421.6002606281033 itp2 = LinearInterpolation(\[1,3200,8600\],\[1,3200,8600\]; extrapolation\_…

---

## [How to parameterize a type on dimensionality of the wrapped array?](https://discourse.julialang.org/t/how-to-parameterize-a-type-on-dimensionality-of-the-wrapped-array/68008)

<div class="topic-metadata">

**Author:** [@tlnagy](https://discourse.julialang.org/u/tlnagy)\
**Replies:** 1\
**Last updated:** [September 11, 2021, 12:16am UTC](https://discourse.julialang.org/t/how-to-parameterize-a-type-on-dimensionality-of-the-wrapped-array/68008 "2021-09-11T00:16:02Z")

</div>

Struggling a bit with parametric types for TiffImages.jl. I want to have two different types of DenseTaggedImage for 2D and 3D images since the ifd variable is a vector for 3D images and 0-dimensional for 2D images. jul…

---

## [Julia 1.7 beta 4 doesn't run in termux Android](https://discourse.julialang.org/t/julia-1-7-beta-4-doesnt-run-in-termux-android/67931)

<div class="topic-metadata">

**Author:** [@evad](https://discourse.julialang.org/u/evad)\
**Replies:** 1\
**Last updated:** [September 10, 2021, 10:40pm UTC](https://discourse.julialang.org/t/julia-1-7-beta-4-doesnt-run-in-termux-android/67931 "2021-09-10T22:40:38Z")

</div>

hi, i have installed voidlinux in termux on Android. and up to beta 3, i can download the tarball and unpack in home folder and run ./julia. for beta 4, i did the same, and running ./julia from bin folder says no such …

---

## [Creating a performant function using metaprogramming](https://discourse.julialang.org/t/creating-a-performant-function-using-metaprogramming/67671)

<div class="topic-metadata">

**Author:** [@elenev](https://discourse.julialang.org/u/elenev)\
**Replies:** 9\
**Last updated:** [September 10, 2021, 10:06pm UTC](https://discourse.julialang.org/t/creating-a-performant-function-using-metaprogramming/67671 "2021-09-10T22:06:09Z")

</div>

I have a function that constructs a NamedTuple out of a vector of numbers subject to some transformation, something like function vec2tuple(x) ( a = x\[1\], b = 1 + exp(x\[2\]), c = 2 + exp(x\[3\]), d = exp(x\[4\]) / (1 + exp(x…

---

## [Namespace with lexical access](https://discourse.julialang.org/t/namespace-with-lexical-access/68010)

<div class="topic-metadata">

**Author:** [@jzr](https://discourse.julialang.org/u/jzr)\
**Replies:** 1\
**Last updated:** [September 10, 2021, 9:46pm UTC](https://discourse.julialang.org/t/namespace-with-lexical-access/68010 "2021-09-10T21:46:50Z")

</div>

I often want to use a namespace for calculating stuff like this FOO = 1 namespace A x = FOO + 1 end This is almost like a module except modules need to import names from the enclosing lexical module, which can be inco…

---

## [Print all the values a function was called with to stdout (equivalent of python's \`inspect.getcallargs\`)?](https://discourse.julialang.org/t/print-all-the-values-a-function-was-called-with-to-stdout-equivalent-of-pythons-inspect-getcallargs/67988)

<div class="topic-metadata">

**Author:** [@mkarikom](https://discourse.julialang.org/u/mkarikom)\
**Replies:** 1\
**Last updated:** [September 10, 2021, 7:47pm UTC](https://discourse.julialang.org/t/print-all-the-values-a-function-was-called-with-to-stdout-equivalent-of-pythons-inspect-getcallargs/67988 "2021-09-10T19:47:15Z")

</div>

Looking for a lightweight way to print all of the following: \<arg/keyword-arg\> .=\> \<value that was passed or default\> here is what the equivalent would be in python: print(getcallargs(show\_params, \*args, \*\*kwargs))

---

## [Two nearly identical loops — why is one faster?](https://discourse.julialang.org/t/two-nearly-identical-loops-why-is-one-faster/67998)

<div class="topic-metadata">

**Author:** [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Replies:** 2\
**Last updated:** [September 10, 2021, 7:03pm UTC](https://discourse.julialang.org/t/two-nearly-identical-loops-why-is-one-faster/67998 "2021-09-10T19:03:49Z")

</div>

The following two functions both evaluate Chebyshev polynomials, using slightly different recurrences that nevertheless require nearly the same number of operations, both are type-stable with 0 allocations, and yet one o…

---

## [Distributed sparse matrix assembly](https://discourse.julialang.org/t/distributed-sparse-matrix-assembly/67986)

<div class="topic-metadata">

**Author:** [@fgerick](https://discourse.julialang.org/u/fgerick)\
**Replies:** 7\
**Last updated:** [September 10, 2021, 5:04pm UTC](https://discourse.julialang.org/t/distributed-sparse-matrix-assembly/67986 "2021-09-10T17:04:40Z")

</div>

Hi, I’m having trouble understanding how Distributed works. I guess it’s something trivial for someone, but I’m no expert on this. I assume it is a mistake related to the movement of data, but I don’t see how to solve t…

---

## [Wondering Why the Variable is Not Used](https://discourse.julialang.org/t/wondering-why-the-variable-is-not-used/67731)

<div class="topic-metadata">

**Author:** [@Edward\_Kong](https://discourse.julialang.org/u/Edward_Kong)\
**Replies:** 15\
**Last updated:** [September 10, 2021, 4:08pm UTC](https://discourse.julialang.org/t/wondering-why-the-variable-is-not-used/67731 "2021-09-10T16:08:01Z")

</div>

I wonder why the grey variable names exist. As I concerned, I think it should have been used.

---

## [Android and iOS apps accessing data in juliadb](https://discourse.julialang.org/t/android-and-ios-apps-accessing-data-in-juliadb/21882)

<div class="topic-metadata">

**Author:** [@eagles051387](https://discourse.julialang.org/u/eagles051387)\
**Replies:** 1\
**Last updated:** [September 10, 2021, 3:44pm UTC](https://discourse.julialang.org/t/android-and-ios-apps-accessing-data-in-juliadb/21882 "2021-09-10T15:44:22Z")

</div>

Hi Guys, How can I have an android or iOS app speak to julia or is it best to pass the data onto an RDBMS and have the mobile apps speak to the RDBMS instead

---

## [How to parallelize something which allocates a lot?](https://discourse.julialang.org/t/how-to-parallelize-something-which-allocates-a-lot/67853)

<div class="topic-metadata">

**Author:** [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Replies:** 10\
**Last updated:** [September 10, 2021, 3:42pm UTC](https://discourse.julialang.org/t/how-to-parallelize-something-which-allocates-a-lot/67853 "2021-09-10T15:42:33Z")

</div>

I have a simulation, which needs around 50MB of RAM and 1 second to finish (lets call it simulate(p)). My problem is that I have to run these simulations around 500 times, which suddenly leads to a slowdown (maybe) due …

---

## [Trouble using Distributed in Juno with non-default environment](https://discourse.julialang.org/t/trouble-using-distributed-in-juno-with-non-default-environment/49603)

<div class="topic-metadata">

**Author:** [@yha](https://discourse.julialang.org/u/yha)\
**Replies:** 2\
**Last updated:** [September 10, 2021, 3:08pm UTC](https://discourse.julialang.org/t/trouble-using-distributed-in-juno-with-non-default-environment/49603 "2021-09-10T15:08:53Z")

</div>

I’m struggling to use Distributed inside Juno without running into what seem to be pre-compilation race conditions. I can’t get @everywhere using to work (for some packages) outside the default environment, though it wor…

---

## [Understanding plot recipes with identical arguments](https://discourse.julialang.org/t/understanding-plot-recipes-with-identical-arguments/67921)

<div class="topic-metadata">

**Author:** [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Replies:** 1\
**Last updated:** [September 10, 2021, 1:23pm UTC](https://discourse.julialang.org/t/understanding-plot-recipes-with-identical-arguments/67921 "2021-09-10T13:23:44Z")

</div>

I just discovered the recipes mechanism in order to avoid having Plots as a package dependency. I currently have a plot1(x::TypeX,y::TypeY) and plot2(x::TypeX,y::TypeY) functions which help present the same data in a di…

---

## [HTTP.request](https://discourse.julialang.org/t/http-request/67981)

<div class="topic-metadata">

**Author:** [@Laco\_Kovac](https://discourse.julialang.org/u/Laco_Kovac)\
**Replies:** 1\
**Last updated:** [September 10, 2021, 1:13pm UTC](https://discourse.julialang.org/t/http-request/67981 "2021-09-10T13:13:11Z")

</div>

I found very strange behaviour of HTTP.request call. My code looks like this: try result = HTTP.request(method, url, headers, body) catch e something end Server returns error, status 501 in my case, but it cou…

---

## [Finding the coefficient in an expression in Symbolics.jl](https://discourse.julialang.org/t/finding-the-coefficient-in-an-expression-in-symbolics-jl/67424)

<div class="topic-metadata">

**Author:** [@fgerick](https://discourse.julialang.org/u/fgerick)\
**Replies:** 2\
**Last updated:** [September 10, 2021, 12:44pm UTC](https://discourse.julialang.org/t/finding-the-coefficient-in-an-expression-in-symbolics-jl/67424 "2021-09-10T12:44:59Z")

</div>

Is there already something like the coeff function of SymPy for Symbolics.jl? E.g. in SymPy I do using SymPy @syms x y f() ex = x^2\*diff(f(x,y),y) + y^2 ex.coeff(diff(f(x,y),y)) # x^2 Can I do the same using Symbolics/…

---

## [Efficient recursive tuple construction](https://discourse.julialang.org/t/efficient-recursive-tuple-construction/67874)

<div class="topic-metadata">

**Author:** [@markmbaum](https://discourse.julialang.org/u/markmbaum)\
**Replies:** 19\
**Last updated:** [September 10, 2021, 12:03pm UTC](https://discourse.julialang.org/t/efficient-recursive-tuple-construction/67874 "2021-09-10T12:03:28Z")

</div>

I’m wondering if there is an efficient way to build a tuple recursively. I’m working with a three-term recurrence relationship (specifically, this one). The first and second terms are known. From them, all the other ter…

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

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