# General Usage

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

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

**Page:** 617

---

## [Simple curve fitting with CurveFit (or alternative)](https://discourse.julialang.org/t/simple-curve-fitting-with-curvefit-or-alternative/58737)

<div class="topic-metadata">

**Author:** [@StatisticalMouse](https://discourse.julialang.org/u/StatisticalMouse)\
**Replies:** 20\
**Last updated:** [April 8, 2021, 8:59pm UTC](https://discourse.julialang.org/t/simple-curve-fitting-with-curvefit-or-alternative/58737 "2021-04-08T20:59:24Z")

</div>

I’d like to try different curves against data to see which of them would best fit. So in this example x0 = collect(1.0:100.0) y0 = x .^ 4.5 f0 = curve\_fit(LinearFit, x0, y0) I’d like to learn just how bad it is, but is…

---

## [Type unstable function because same variable name used twice](https://discourse.julialang.org/t/type-unstable-function-because-same-variable-name-used-twice/58810)

<div class="topic-metadata">

**Author:** [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)\
**Replies:** 10\
**Last updated:** [April 8, 2021, 8:21pm UTC](https://discourse.julialang.org/t/type-unstable-function-because-same-variable-name-used-twice/58810 "2021-04-08T20:21:19Z")

</div>

Hey, I cannot come up with a minimal example yet, but I encountered that my function return was type unstable because of such a construct: function foo(x) # some code y = (1, 2) # first y = \[x\[1\] for i …

---

## [Is a Phillips-Peron Test Available?](https://discourse.julialang.org/t/is-a-phillips-peron-test-available/58793)

<div class="topic-metadata">

**Author:** [@RalphH](https://discourse.julialang.org/u/RalphH)\
**Replies:** 5\
**Last updated:** [April 8, 2021, 7:57pm UTC](https://discourse.julialang.org/t/is-a-phillips-peron-test-available/58793 "2021-04-08T19:57:12Z")

</div>

Hello everyone, is a Phillips-Peron test available in Julia? If not, when will one be available? I have searched but can’t find one. I’m working with heteroskedastic data, so the ADF test isn’t adequate, and replacing J…

---

## [Translation groupby and agg and join python to julia](https://discourse.julialang.org/t/translation-groupby-and-agg-and-join-python-to-julia/58835)

<div class="topic-metadata">

**Author:** [@Rafael\_Brus](https://discourse.julialang.org/u/Rafael_Brus)\
**Replies:** 4\
**Last updated:** [April 8, 2021, 3:33pm UTC](https://discourse.julialang.org/t/translation-groupby-and-agg-and-join-python-to-julia/58835 "2021-04-08T15:33:49Z")

</div>

How do I translate this python code to julia: V1 = \[“co\_seq\_atend”, “co\_seq\_atend\_prof”, “co\_prontuario”, “no\_status\_atend”, “st\_atend\_prof”, “no\_tipo\_atend\_prof”, “no\_profissional”, “co\_cbo\_2002”, “nu\_cnes”, “nu\_ine”,…

---

## [Zygote.jl: DimensionMismatch: matrix is not square error](https://discourse.julialang.org/t/zygote-jl-dimensionmismatch-matrix-is-not-square-error/58839)

<div class="topic-metadata">

**Author:** [@Richard-Li](https://discourse.julialang.org/u/Richard-Li)\
**Replies:** 2\
**Last updated:** [April 8, 2021, 3:27pm UTC](https://discourse.julialang.org/t/zygote-jl-dimensionmismatch-matrix-is-not-square-error/58839 "2021-04-08T15:27:55Z")

</div>

Hi, I am using Zygote.jl. I’d like to change a matrix from 3x3 to 5x3 like this MWE: using Zygote using LinearAlgebra function test( c ) m = rand(3,3) \* c @show m M = Matrix(1.0I, 5, 3) \* m @show M …

---

## [Unreachable reached when computing the Jacobian with Zygote if an other package is imported before, on Julia \< 1.6](https://discourse.julialang.org/t/unreachable-reached-when-computing-the-jacobian-with-zygote-if-an-other-package-is-imported-before-on-julia-1-6/58828)

<div class="topic-metadata">

**Author:** [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Replies:** 2\
**Last updated:** [April 8, 2021, 3:10pm UTC](https://discourse.julialang.org/t/unreachable-reached-when-computing-the-jacobian-with-zygote-if-an-other-package-is-imported-before-on-julia-1-6/58828 "2021-04-08T15:10:56Z")

</div>

I am experiencing a strange Julia crash when I import BetaML before computing a gradient operation with Zygote, but if I first do this operation, then I import BetaML (or using BetaML) and then do again the gradient oper…

---

## [Multiple dispatch with and without missing to same function?](https://discourse.julialang.org/t/multiple-dispatch-with-and-without-missing-to-same-function/58821)

<div class="topic-metadata">

**Author:** [@Daneel](https://discourse.julialang.org/u/Daneel)\
**Replies:** 13\
**Last updated:** [April 8, 2021, 3:08pm UTC](https://discourse.julialang.org/t/multiple-dispatch-with-and-without-missing-to-same-function/58821 "2021-04-08T15:08:07Z")

</div>

I have a function which takes data loaded from a file. Normally it’s all Matrix{Float64} but sometimes there are some missing values, Matrix{Union{Missing, Float64}. How would I write a function to take a Number matrix w…

---

## [What is Base.maybeview?](https://discourse.julialang.org/t/what-is-base-maybeview/58820)

<div class="topic-metadata">

**Author:** [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Replies:** 9\
**Last updated:** [April 8, 2021, 2:23pm UTC](https://discourse.julialang.org/t/what-is-base-maybeview/58820 "2021-04-08T14:23:38Z")

</div>

I found usage of Base.maybeview in LSHFunctions. What is it? (no docs). How is it different from view? thanks.

---

## [How do I save (and later load) fitted KernelPCA model using MultivariateStats.jl](https://discourse.julialang.org/t/how-do-i-save-and-later-load-fitted-kernelpca-model-using-multivariatestats-jl/58833)

<div class="topic-metadata">

**Author:** [@Patrick\_Soundy](https://discourse.julialang.org/u/Patrick_Soundy)\
**Replies:** 0\
**Last updated:** [April 8, 2021, 1:52pm UTC](https://discourse.julialang.org/t/how-do-i-save-and-later-load-fitted-kernelpca-model-using-multivariatestats-jl/58833 "2021-04-08T13:52:54Z")

</div>

I’m fitting a simple KPCA to data: ‘’‘KPCAModel = fit(KernelPCA, MyArray; kernel=(x,y)-\>exp(-norm(x-y)^2/(2\*σ^2)), maxoutdim=NumFactors, inverse=true)’‘’ How do I save the model in Julia to load it back to transform ne…

---

## [Using FLoops.jl to update array counters](https://discourse.julialang.org/t/using-floops-jl-to-update-array-counters/58805)

<div class="topic-metadata">

**Author:** [@Fathya.Salih](https://discourse.julialang.org/u/Fathya.Salih)\
**Replies:** 2\
**Last updated:** [April 8, 2021, 1:22pm UTC](https://discourse.julialang.org/t/using-floops-jl-to-update-array-counters/58805 "2021-04-08T13:22:57Z")

</div>

Hey, all! I am trying to parallelize a for-loop that updates array and scalar counters. I am able to reduce the scalar counters, but I get this error when I add the array counter. ERROR: LoadError: syntax: invalid synt…

---

## [Plots visualization differences between VSCode and export](https://discourse.julialang.org/t/plots-visualization-differences-between-vscode-and-export/58817)

<div class="topic-metadata">

**Author:** [@felcbd](https://discourse.julialang.org/u/felcbd)\
**Replies:** 4\
**Last updated:** [April 8, 2021, 12:05pm UTC](https://discourse.julialang.org/t/plots-visualization-differences-between-vscode-and-export/58817 "2021-04-08T12:05:14Z")

</div>

Hello everyone, Was doing some plotting to display a Gantt Chart with VegaLite, and I tried the save() function I saw on a basic example for VegaLite usage. But there is some modifications from the save() function, com…

---

## [Question about program design with ComponentArrays](https://discourse.julialang.org/t/question-about-program-design-with-componentarrays/58732)

<div class="topic-metadata">

**Author:** [@amrods](https://discourse.julialang.org/u/amrods)\
**Replies:** 5\
**Last updated:** [April 8, 2021, 11:42am UTC](https://discourse.julialang.org/t/question-about-program-design-with-componentarrays/58732 "2021-04-08T11:42:25Z")

</div>

I’m retaking a program I did some time ago, trying to speed it up. I am using ComponentArrays because it is very easy to organize data and parameters with it. Consider this: using ComponentArrays using Parameters: @unpa…

---

## [Accessing struct via Symbol](https://discourse.julialang.org/t/accessing-struct-via-symbol/58809)

<div class="topic-metadata">

**Author:** [@mrVeng](https://discourse.julialang.org/u/mrVeng)\
**Replies:** 5\
**Last updated:** [April 8, 2021, 11:00am UTC](https://discourse.julialang.org/t/accessing-struct-via-symbol/58809 "2021-04-08T11:00:28Z")

</div>

Dear all, Is there a reason why this works: struct Test1{A, B} a :: A b :: B end test1 = Test1(1., 2.) test1.:a #1 but this does not work? \_a = :a test1.\_a # type Test1 has no field \_a In my case I would like to u…

---

## [Broadcast over a specific dimension of array](https://discourse.julialang.org/t/broadcast-over-a-specific-dimension-of-array/43158)

<div class="topic-metadata">

**Author:** [@white-c](https://discourse.julialang.org/u/white-c)\
**Replies:** 7\
**Last updated:** [April 8, 2021, 10:23am UTC](https://discourse.julialang.org/t/broadcast-over-a-specific-dimension-of-array/43158 "2021-04-08T10:23:28Z")

</div>

Hello, Julians! I have a 3 dimensional complex F64 array. I want to run the inv() over the inner two dimensions and broadcast along the outer dimension. When I try simple broadcasting inv.(A) I get different results tha…

---

## [Fast computation of row-wise Kronecker product (Khatri-Rao product)](https://discourse.julialang.org/t/fast-computation-of-row-wise-kronecker-product-khatri-rao-product/58762)

<div class="topic-metadata">

**Author:** [@Germinator](https://discourse.julialang.org/u/Germinator)\
**Replies:** 5\
**Last updated:** [April 8, 2021, 7:31am UTC](https://discourse.julialang.org/t/fast-computation-of-row-wise-kronecker-product-khatri-rao-product/58762 "2021-04-08T07:31:24Z")

</div>

Hello! I have recently started to migrate to Julia, and decided to port some of my Matlab code. I am struggling to make a performant row-wise Kronecker product (Khatri-Rao product) implementation for two or three matrice…

---

## [Calculate deseasonalized anomalies](https://discourse.julialang.org/t/calculate-deseasonalized-anomalies/58753)

<div class="topic-metadata">

**Author:** [@mixstam1453](https://discourse.julialang.org/u/mixstam1453)\
**Replies:** 4\
**Last updated:** [April 8, 2021, 6:47am UTC](https://discourse.julialang.org/t/calculate-deseasonalized-anomalies/58753 "2021-04-08T06:47:00Z")

</div>

Hi to everyone! I am new in Julia and i have monthly values of a climate variable. I calculate the annual cycle but i can’t find the way to compute the anomalies. Here is the part of the code: using DataFrames ; using …

---

## [Julia 1.6.0 packages installation](https://discourse.julialang.org/t/julia-1-6-0-packages-installation/58552)

<div class="topic-metadata">

**Author:** [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Replies:** 10\
**Last updated:** [April 8, 2021, 5:49am UTC](https://discourse.julialang.org/t/julia-1-6-0-packages-installation/58552 "2021-04-08T05:49:30Z")

</div>

How to solve this problem: Some packages have a happy installation and others do not! (@v1.6) pkg\> add Plots Updating registry at \`C:\\Users\\hermesr\\.julia\\registries\\General\` ┌ Warning: could not download https://p…

---

## [Weird duplicated entries with different values in SparseMatrixCSC](https://discourse.julialang.org/t/weird-duplicated-entries-with-different-values-in-sparsematrixcsc/58449)

<div class="topic-metadata">

**Author:** [@Richard-Li](https://discourse.julialang.org/u/Richard-Li)\
**Replies:** 9\
**Last updated:** [April 8, 2021, 1:47am UTC](https://discourse.julialang.org/t/weird-duplicated-entries-with-different-values-in-sparsematrixcsc/58449 "2021-04-08T01:47:01Z")

</div>

Hi, I found a very weird thing when using SparseMatrixCSC: K is a SparseMatrixCSC created from some complicated process (Finite element analysis application), here I show part of it: K = spzeros(ndof, ndof) #ndof : nu…

---

## [Running a specific julia environment from a crontab](https://discourse.julialang.org/t/running-a-specific-julia-environment-from-a-crontab/58799)

<div class="topic-metadata">

**Author:** [@SpinolaHours](https://discourse.julialang.org/u/SpinolaHours)\
**Replies:** 3\
**Last updated:** [April 8, 2021, 1:27am UTC](https://discourse.julialang.org/t/running-a-specific-julia-environment-from-a-crontab/58799 "2021-04-08T01:27:24Z")

</div>

Hi there. My goal is to run a Julia script from crontab. For this I need to be able to activate the correct Julia environment from the command line. I’m not sure how to do this. A possible solution I’ve found is to ad…

---

## [How Do I Most Effectively Use Multiple Dispatch in Data Science Workflows?](https://discourse.julialang.org/t/how-do-i-most-effectively-use-multiple-dispatch-in-data-science-workflows/58772)

<div class="topic-metadata">

**Author:** [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Replies:** 11\
**Last updated:** [April 7, 2021, 10:29pm UTC](https://discourse.julialang.org/t/how-do-i-most-effectively-use-multiple-dispatch-in-data-science-workflows/58772 "2021-04-07T22:29:20Z")

</div>

Hi all, Say if I have two DataFrames: df1 and df2. They have unique values but have the same column names: Cost, Customer, and Product. As I move forward with my data processing, sometimes, I want to harmonize the DataF…

---

## [Types with multiple supertypes](https://discourse.julialang.org/t/types-with-multiple-supertypes/58787)

<div class="topic-metadata">

**Author:** [@IljaK91](https://discourse.julialang.org/u/IljaK91)\
**Replies:** 4\
**Last updated:** [April 7, 2021, 7:33pm UTC](https://discourse.julialang.org/t/types-with-multiple-supertypes/58787 "2021-04-07T19:33:44Z")

</div>

Hey everybody, I have a model in which I can have different setups. There are in principle 2x2 combinations. Let’s say models can be A1, A2, B1, B2. I now have types that are specialized for each type. Some function be…

---

## [How can I parse a \`UnitfulQuantity\` to return a unit describing only the \`Time\` dimension?](https://discourse.julialang.org/t/how-can-i-parse-a-unitfulquantity-to-return-a-unit-describing-only-the-time-dimension/58780)

<div class="topic-metadata">

**Author:** [@cadojo](https://discourse.julialang.org/u/cadojo)\
**Replies:** 1\
**Last updated:** [April 7, 2021, 6:17pm UTC](https://discourse.julialang.org/t/how-can-i-parse-a-unitfulquantity-to-return-a-unit-describing-only-the-time-dimension/58780 "2021-04-07T18:17:04Z")

</div>

I have a function where I want to parse a Unitful.Quantity argument provided by the user for only the Time dimensioned unit. For example… f(1u"km/s") # should return u"s" f(1u"km/d") # should return u"d" Is this suppor…

---

## [How to freeze a single weight of a layer?](https://discourse.julialang.org/t/how-to-freeze-a-single-weight-of-a-layer/58279)

<div class="topic-metadata">

**Author:** [@March-08](https://discourse.julialang.org/u/March-08)\
**Replies:** 5\
**Last updated:** [April 7, 2021, 4:24pm UTC](https://discourse.julialang.org/t/how-to-freeze-a-single-weight-of-a-layer/58279 "2021-04-07T16:24:11Z")

</div>

Is there a way to freeze one single weight instead of an entire layer ? Flux.delete! function is able to freeze just the layer and not one single parameter. function micronet() simplenet = gpu(Chain( Dense(2…

---

## [Ctime() in Windows 10](https://discourse.julialang.org/t/ctime-in-windows-10/58755)

<div class="topic-metadata">

**Author:** [@Brad\_Carman](https://discourse.julialang.org/u/Brad_Carman)\
**Replies:** 0\
**Last updated:** [April 7, 2021, 2:20pm UTC](https://discourse.julialang.org/t/ctime-in-windows-10/58755 "2021-04-07T14:20:40Z")

</div>

It appears that the ctime() function does not provide the correct “creation time” of a file in Windows 10 (using Julia v1.6). I was wondering if anyone has successfully done a ccall to kernel32.dll to get the correct cr…

---

## [Why putting a function argument first](https://discourse.julialang.org/t/why-putting-a-function-argument-first/58700)

<div class="topic-metadata">

**Author:** [@qsong](https://discourse.julialang.org/u/qsong)\
**Replies:** 7\
**Last updated:** [April 7, 2021, 12:24pm UTC](https://discourse.julialang.org/t/why-putting-a-function-argument-first/58700 "2021-04-07T12:24:21Z")

</div>

Although it appears #1 convention on style guide of the docs to write functions for a long time till Julia 1.6 now, it brings difficulty on some user cases like manipulating data and piping. I was wondering if it would m…

---

## [Optimization code](https://discourse.julialang.org/t/optimization-code/58744)

<div class="topic-metadata">

**Author:** [@dires](https://discourse.julialang.org/u/dires)\
**Replies:** 1\
**Last updated:** [April 7, 2021, 12:10pm UTC](https://discourse.julialang.org/t/optimization-code/58744 "2021-04-07T12:10:45Z")

</div>

I have got a warning message below, ┌ Warning: with\_optimizer is deprecated. Adapt the following example to update your code: │ with\_optimizer(Ipopt.Optimizer) becomes Ipopt.Optimizer. │ caller = top-level scope at …

---

## [Adding package to project by identifying directory (from outside)](https://discourse.julialang.org/t/adding-package-to-project-by-identifying-directory-from-outside/58747)

<div class="topic-metadata">

**Author:** [@Mrion](https://discourse.julialang.org/u/Mrion)\
**Replies:** 2\
**Last updated:** [April 7, 2021, 11:37am UTC](https://discourse.julialang.org/t/adding-package-to-project-by-identifying-directory-from-outside/58747 "2021-04-07T11:37:09Z")

</div>

Hi! Is there a way to add package to project from outside of project? Something like Pkg.add(required\_package, path\_to\_project\_where\_package\_should\_be\_added)

---

## [For-loop vs list-comprehension](https://discourse.julialang.org/t/for-loop-vs-list-comprehension/58702)

<div class="topic-metadata">

**Author:** [@pedrobtz](https://discourse.julialang.org/u/pedrobtz)\
**Replies:** 15\
**Last updated:** [April 7, 2021, 10:56am UTC](https://discourse.julialang.org/t/for-loop-vs-list-comprehension/58702 "2021-04-07T10:56:12Z")

</div>

Why isn’t the list-comprehension as fast as the for-loop? using Random using BenchmarkTools y = zeros(UInt8,256); y\[UInt8('A')\] = UInt8('U'); y\[UInt8('C')\] = UInt8('G'); y\[UInt8('G')\] = UInt8('C'); y\[UInt8('T')\] = UInt…

---

## [\`Using\` doesn't work inside custom module](https://discourse.julialang.org/t/using-doesnt-work-inside-custom-module/58742)

<div class="topic-metadata">

**Author:** [@Sunny](https://discourse.julialang.org/u/Sunny)\
**Replies:** 2\
**Last updated:** [April 7, 2021, 10:52am UTC](https://discourse.julialang.org/t/using-doesnt-work-inside-custom-module/58742 "2021-04-07T10:52:00Z")

</div>

I want to export a function from a custom module that uses some package inside itself, but it works in a unexpected way for me module A export f using StatsBase f(x) = StatsBase.sample(\[x,0\]) end using .A f(1) Output …

---

## [(Plots) how to set color of y-axis border and ticks](https://discourse.julialang.org/t/plots-how-to-set-color-of-y-axis-border-and-ticks/58730)

<div class="topic-metadata">

**Author:** [@iHany](https://discourse.julialang.org/u/iHany)\
**Replies:** 1\
**Last updated:** [April 7, 2021, 9:32am UTC](https://discourse.julialang.org/t/plots-how-to-set-color-of-y-axis-border-and-ticks/58730 "2021-04-07T09:32:04Z")

</div>

Hi, I’m using Plots with GR backend. I’d like to know how to set the color of y-axis border and ticks.

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

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