# General Usage

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

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

**Page:** 791

---

## [How would I sort user transactions by date, and only keep the N most recent entries](https://discourse.julialang.org/t/how-would-i-sort-user-transactions-by-date-and-only-keep-the-n-most-recent-entries/34261)

<div class="topic-metadata">

**Author:** [@Julia1](https://discourse.julialang.org/u/Julia1)\
**Replies:** 8\
**Last updated:** [February 6, 2020, 11:20pm UTC](https://discourse.julialang.org/t/how-would-i-sort-user-transactions-by-date-and-only-keep-the-n-most-recent-entries/34261 "2020-02-06T23:20:37Z")

</div>

Hi how’s it going? I have a dataframe where I have unique user entries and the date as one of the features. I know how to sort by date, but I’m having difficulty extracting say the last 5 entries per user. In Pandas the…

---

## [Style question: ternary operator or short circuit operator or if-end](https://discourse.julialang.org/t/style-question-ternary-operator-or-short-circuit-operator-or-if-end/34224)

<div class="topic-metadata">

**Author:** [@Gus\_Hart](https://discourse.julialang.org/u/Gus_Hart)\
**Replies:** 17\
**Last updated:** [February 6, 2020, 7:17pm UTC](https://discourse.julialang.org/t/style-question-ternary-operator-or-short-circuit-operator-or-if-end/34224 "2020-02-06T19:17:54Z")

</div>

I often find myself wishing the following syntax worked: if a \< 0 then a = 0 (get the condition, and statement that follows, on a single line. No need for end or ;) This works fine: if a \< 0; a = 0; end, but feels jus…

---

## [Sparse matrix slicing](https://discourse.julialang.org/t/sparse-matrix-slicing/34263)

<div class="topic-metadata">

**Author:** [@martincornejo](https://discourse.julialang.org/u/martincornejo)\
**Replies:** 1\
**Last updated:** [February 6, 2020, 5:59pm UTC](https://discourse.julialang.org/t/sparse-matrix-slicing/34263 "2020-02-06T17:59:12Z")

</div>

I have a doubt regarding slicing sparse matrices. For a n x m sparse matrix (for example A = sparse(\[1; 2; 3\], 1:3, 1.0, 18, 3)), when slicing the first row A\[1,:\] the result is a sparse vector, but instead of a row vect…

---

## [Distributions does not play nicely with PackageCompilerX](https://discourse.julialang.org/t/distributions-does-not-play-nicely-with-packagecompilerx/34255)

<div class="topic-metadata">

**Author:** [@PGS62](https://discourse.julialang.org/u/PGS62)\
**Replies:** 2\
**Last updated:** [February 6, 2020, 5:17pm UTC](https://discourse.julialang.org/t/distributions-does-not-play-nicely-with-packagecompilerx/34255 "2020-02-06T17:17:34Z")

</div>

Using PackageCompilerX, I wish to create an app from a package that uses functions in Distributions. Unfortunately, create\_app fails as shown below. I’m not using much functionality from Distributions so I should be abl…

---

## [How to use PyCall to connect to Splunk's SDK-python?](https://discourse.julialang.org/t/how-to-use-pycall-to-connect-to-splunks-sdk-python/34226)

<div class="topic-metadata">

**Author:** [@Aizzaac](https://discourse.julialang.org/u/Aizzaac)\
**Replies:** 2\
**Last updated:** [February 6, 2020, 3:44pm UTC](https://discourse.julialang.org/t/how-to-use-pycall-to-connect-to-splunks-sdk-python/34226 "2020-02-06T15:44:58Z")

</div>

Hi I want to connect to Splunk using a Python SDK. This is the code in python: import splunklib.client as client HOST = "localhost" PORT = 8089 USERNAME = "admin" PASSWORD = "passwdSPLUNK" # Create a Service instanc…

---

## [Understanding Logging in Julia](https://discourse.julialang.org/t/understanding-logging-in-julia/34252)

<div class="topic-metadata">

**Author:** [@Gregstrq](https://discourse.julialang.org/u/Gregstrq)\
**Replies:** 1\
**Last updated:** [February 6, 2020, 3:17pm UTC](https://discourse.julialang.org/t/understanding-logging-in-julia/34252 "2020-02-06T15:17:45Z")

</div>

Hi, guys. I am trying to understand how to use Julia Logging system. For that I am now reading through the julia docs and the corresponding source code. I have a question about the implementation of SimpleLogger (see l…

---

## [Maintain connection in ZMQ](https://discourse.julialang.org/t/maintain-connection-in-zmq/34243)

<div class="topic-metadata">

**Author:** [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Replies:** 1\
**Last updated:** [February 6, 2020, 2:41pm UTC](https://discourse.julialang.org/t/maintain-connection-in-zmq/34243 "2020-02-06T14:41:04Z")

</div>

I am trying to establish a socket that listens for requests. Unfortunately, due to a combination of sparse documentation and my lack of familiarity with networking, I am unable to accomplish this through normal means. T…

---

## [HELP: Implementing K-means from scratch with Julia](https://discourse.julialang.org/t/help-implementing-k-means-from-scratch-with-julia/34249)

<div class="topic-metadata">

**Author:** [@PyDataBlog](https://discourse.julialang.org/u/PyDataBlog)\
**Replies:** 4\
**Last updated:** [February 6, 2020, 2:28pm UTC](https://discourse.julialang.org/t/help-implementing-k-means-from-scratch-with-julia/34249 "2020-02-06T14:28:15Z")

</div>

Hi everyone, I am currently stuck trying to port an existing Julia code. Basically a code that builds a simple implementation of the K-means clustering algorithm. Here’s the testing data generated from sklearn: # Repla…

---

## [Handle exception with the problem interface of DifferentialEquations](https://discourse.julialang.org/t/handle-exception-with-the-problem-interface-of-differentialequations/34228)

<div class="topic-metadata">

**Author:** [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Replies:** 5\
**Last updated:** [February 6, 2020, 2:25pm UTC](https://discourse.julialang.org/t/handle-exception-with-the-problem-interface-of-differentialequations/34228 "2020-02-06T14:25:45Z")

</div>

Hello, I have an ODE problem with multiple callbacks (continuous and discrete ones). For some initial conditions, the computation of the right hand side will return an ArgumentError, is it possible to use the function t…

---

## [Issue with 1.5 month old code based on CuArrays](https://discourse.julialang.org/t/issue-with-1-5-month-old-code-based-on-cuarrays/34248)

<div class="topic-metadata">

**Author:** [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Replies:** 3\
**Last updated:** [February 6, 2020, 1:57pm UTC](https://discourse.julialang.org/t/issue-with-1-5-month-old-code-based-on-cuarrays/34248 "2020-02-06T13:57:14Z")

</div>

Hi, I am updating my library PseudoArcLengthContinuation.jl and one of the tutorials based on CuArrays does not work anymore. It used to work by the end of December. Can someone explain me the error please? Thank you …

---

## [Keyword argument constructor breaks Incomplete constructor](https://discourse.julialang.org/t/keyword-argument-constructor-breaks-incomplete-constructor/34198)

<div class="topic-metadata">

**Author:** [@milesf](https://discourse.julialang.org/u/milesf)\
**Replies:** 6\
**Last updated:** [February 6, 2020, 8:07am UTC](https://discourse.julialang.org/t/keyword-argument-constructor-breaks-incomplete-constructor/34198 "2020-02-06T08:07:12Z")

</div>

julia\> mutable struct Foo x::Float64 y::Float64 Foo() = new() Foo(;x::Float64, y::Float64) = new(x, y) end julia\> Foo() ERROR: UndefKeywordError: keyword argument x no…

---

## [Accesing a Registry on Private Github](https://discourse.julialang.org/t/accesing-a-registry-on-private-github/19997)

<div class="topic-metadata">

**Author:** [@Andrew\_Gibb](https://discourse.julialang.org/u/Andrew_Gibb)\
**Replies:** 17\
**Last updated:** [February 6, 2020, 12:17am UTC](https://discourse.julialang.org/t/accesing-a-registry-on-private-github/19997 "2020-02-06T00:17:03Z")

</div>

I’ve just made myself a private registry for my work packages, following the nice instructions here. My organisation uses private github for most of our code, so I’ve put it there. When I try to do a package update, Pkg …

---

## [Scalar parameter doesn't update in Flux, but array does](https://discourse.julialang.org/t/scalar-parameter-doesnt-update-in-flux-but-array-does/32548)

<div class="topic-metadata">

**Author:** [@jonasaugust](https://discourse.julialang.org/u/jonasaugust)\
**Replies:** 10\
**Last updated:** [February 5, 2020, 10:06pm UTC](https://discourse.julialang.org/t/scalar-parameter-doesnt-update-in-flux-but-array-does/32548 "2020-02-05T22:06:30Z")

</div>

When I try to minimize a quadratic function f(x) in a single, scalar parameter x via gradient descent in Flux, there is no progression (no change in x), but the single-component array version of the same works correctly: …

---

## [Cloning a project - out of memory error](https://discourse.julialang.org/t/cloning-a-project-out-of-memory-error/34218)

<div class="topic-metadata">

**Author:** [@lwhitefox](https://discourse.julialang.org/u/lwhitefox)\
**Replies:** 1\
**Last updated:** [February 5, 2020, 7:58pm UTC](https://discourse.julialang.org/t/cloning-a-project-out-of-memory-error/34218 "2020-02-05T19:58:39Z")

</div>

I am trying to instantiate a Julia project environment in a virtual linux machine. I copy the relevant Project.toml, and the Pkg system sees it correctly. However, when I type instantiate I keep getting the errors simi…

---

## [How to write code in Julia from Python](https://discourse.julialang.org/t/how-to-write-code-in-julia-from-python/34214)

<div class="topic-metadata">

**Author:** [@Aizzaac](https://discourse.julialang.org/u/Aizzaac)\
**Replies:** 10\
**Last updated:** [February 5, 2020, 7:34pm UTC](https://discourse.julialang.org/t/how-to-write-code-in-julia-from-python/34214 "2020-02-05T19:34:48Z")

</div>

Hi I am struggling with my first script with Julia. In Python I am using this piece of code to have the PATH of ‘splunk -sdk-python’. import sys, os pa = os.path.join(os.path.abspath(os.path.join('', os.pardir)), "sp…

---

## [Kmeans problem](https://discourse.julialang.org/t/kmeans-problem/34210)

<div class="topic-metadata">

**Author:** [@muhammetfaik](https://discourse.julialang.org/u/muhammetfaik)\
**Replies:** 1\
**Last updated:** [February 5, 2020, 5:18pm UTC](https://discourse.julialang.org/t/kmeans-problem/34210 "2020-02-05T17:18:38Z")

</div>

https://github.com/muhammetfaik/julia-tutorial/issues/1

---

## [Save data frame with special characters in csv](https://discourse.julialang.org/t/save-data-frame-with-special-characters-in-csv/34022)

<div class="topic-metadata">

**Author:** [@jayce\_ram](https://discourse.julialang.org/u/jayce_ram)\
**Replies:** 5\
**Last updated:** [February 5, 2020, 5:06pm UTC](https://discourse.julialang.org/t/save-data-frame-with-special-characters-in-csv/34022 "2020-02-05T17:06:28Z")

</div>

The column names of my dataframe has special character like "€. Before updating to v1.3, I was able to write my df in a csv file and keeping the different symbols. However, after updating the csv file doesn’t recognize …

---

## [Checking if all the array's elements are positive](https://discourse.julialang.org/t/checking-if-all-the-arrays-elements-are-positive/34206)

<div class="topic-metadata">

**Author:** [@marouane1994](https://discourse.julialang.org/u/marouane1994)\
**Replies:** 8\
**Last updated:** [February 5, 2020, 3:08pm UTC](https://discourse.julialang.org/t/checking-if-all-the-arrays-elements-are-positive/34206 "2020-02-05T15:08:53Z")

</div>

in the usual case i can make sure if all the array’s elements are positive using the nonneg(x)now it’s not working for me everytime i try to use it, an error raises with nonneg is not defined is it deprecated or what?

---

## [Run Parallel Python in Julia](https://discourse.julialang.org/t/run-parallel-python-in-julia/34201)

<div class="topic-metadata">

**Author:** [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Replies:** 3\
**Last updated:** [February 5, 2020, 1:37pm UTC](https://discourse.julialang.org/t/run-parallel-python-in-julia/34201 "2020-02-05T13:37:12Z")

</div>

How does PyCall work under the hood. Can I run parallel python processes within Julia?

---

## [Suggestions for testing with dependencies from other languages](https://discourse.julialang.org/t/suggestions-for-testing-with-dependencies-from-other-languages/34207)

<div class="topic-metadata">

**Author:** [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Replies:** 0\
**Last updated:** [February 5, 2020, 1:03pm UTC](https://discourse.julialang.org/t/suggestions-for-testing-with-dependencies-from-other-languages/34207 "2020-02-05T13:03:00Z")

</div>

Hi, The tl;dr of this post is basically how much hassle it is to depend on pre-compiled c artifacts v.s. just using an existing python wrapper for said artifacts. I started the (perhaps foolish) endeavour to implement …

---

## [Memory allocation in generator with zip](https://discourse.julialang.org/t/memory-allocation-in-generator-with-zip/1903)

<div class="topic-metadata">

**Author:** [@gasagna](https://discourse.julialang.org/u/gasagna)\
**Replies:** 2\
**Last updated:** [February 5, 2020, 9:56am UTC](https://discourse.julialang.org/t/memory-allocation-in-generator-with-zip/1903 "2020-02-05T09:56:17Z")

</div>

Hi, I am experiencing some suspect memory allocation using a generator containing a zip iterator. The minimal example is this: as = Vector{Float64}\[randn(5) for i = 1:200000\] bs = Vector{Float64}\[randn(5) for i = 1:200…

---

## [Define sub-types or not?](https://discourse.julialang.org/t/define-sub-types-or-not/34183)

<div class="topic-metadata">

**Author:** [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Replies:** 2\
**Last updated:** [February 5, 2020, 7:08am UTC](https://discourse.julialang.org/t/define-sub-types-or-not/34183 "2020-02-05T07:08:04Z")

</div>

Consider the following contrived example: Suppose I wanted to implement my own custom Weight types and let’s say that some of them can be converted to standard units (pounds, kilograms, etc.) while others (for some stra…

---

## [Semi-deep copy of array](https://discourse.julialang.org/t/semi-deep-copy-of-array/34135)

<div class="topic-metadata">

**Author:** [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Replies:** 8\
**Last updated:** [February 4, 2020, 9:56pm UTC](https://discourse.julialang.org/t/semi-deep-copy-of-array/34135 "2020-02-04T21:56:16Z")

</div>

I have defined a struct MyType and the corresponding method copy(a::MyType). Now I would like to have a method to copy an Array of MyType, applying this method to each element of the array. What is the proper Julian way…

---

## [Efficient way to read large array from binary file in slices?](https://discourse.julialang.org/t/efficient-way-to-read-large-array-from-binary-file-in-slices/6847)

<div class="topic-metadata">

**Author:** [@tlnagy](https://discourse.julialang.org/u/tlnagy)\
**Replies:** 12\
**Last updated:** [February 4, 2020, 9:43pm UTC](https://discourse.julialang.org/t/efficient-way-to-read-large-array-from-binary-file-in-slices/6847 "2020-02-04T21:43:33Z")

</div>

I’ve written a TIFF parser (GitHub - tlnagy/OMETIFF.jl: I/O operations for OME-TIFF files in Julia) and there are still some inefficiencies that I would like to fix. One problem is that I allocate a large array that wil…

---

## [WeakKeyDict(x=\>x) holds on to memory](https://discourse.julialang.org/t/weakkeydict-x-x-holds-on-to-memory/34187)

<div class="topic-metadata">

**Author:** [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Replies:** 1\
**Last updated:** [February 4, 2020, 9:39pm UTC](https://discourse.julialang.org/t/weakkeydict-x-x-holds-on-to-memory/34187 "2020-02-04T21:39:54Z")

</div>

julia\> wk = let x = Ref{Any}(nothing) WeakKeyDict(x=\>x) end WeakKeyDict{Base.RefValue{Any},Base.RefValue{Any}} with 1 entry: RefValue{Any}(nothing) =\> RefValue{Any}(nothing) julia\> GC.gc() julia\> GC…

---

## [Creating multiple variables with consecutive names using a for loop](https://discourse.julialang.org/t/creating-multiple-variables-with-consecutive-names-using-a-for-loop/34177)

<div class="topic-metadata">

**Author:** [@HoldenCaulfield](https://discourse.julialang.org/u/HoldenCaulfield)\
**Replies:** 8\
**Last updated:** [February 4, 2020, 6:09pm UTC](https://discourse.julialang.org/t/creating-multiple-variables-with-consecutive-names-using-a-for-loop/34177 "2020-02-04T18:09:14Z")

</div>

I want to create several variables with consecutive names. For instance, I want to create 100 variables like variable\_1, variable\_2, … , variable\_100, and maybe assign a random vector to each of them, e.g. variable\_1 = r…

---

## [Stop gradients from propagating through some branches of computation tree in Flux](https://discourse.julialang.org/t/stop-gradients-from-propagating-through-some-branches-of-computation-tree-in-flux/33392)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 9\
**Last updated:** [February 4, 2020, 6:02pm UTC](https://discourse.julialang.org/t/stop-gradients-from-propagating-through-some-branches-of-computation-tree-in-flux/33392 "2020-02-04T18:02:24Z")

</div>

Is it possible to perform some computation in my loss function that is excluded from the gradient, while still using the simple Flux.train! API? Tensorflow and Keras have something called stop\_gradient , which can be ap…

---

## [How to garbage collect a DistributedArray for sure?](https://discourse.julialang.org/t/how-to-garbage-collect-a-distributedarray-for-sure/34174)

<div class="topic-metadata">

**Author:** [@Gregstrq](https://discourse.julialang.org/u/Gregstrq)\
**Replies:** 0\
**Last updated:** [February 4, 2020, 4:28pm UTC](https://discourse.julialang.org/t/how-to-garbage-collect-a-distributedarray-for-sure/34174 "2020-02-04T16:28:52Z")

</div>

Let’s say I create a DistributedArray but then reassign the variable to a new one: using Distributed addprocs(1) using DistributedArrays, LinearAlgebra da = DArray(\[@spawnat wid LinearAlgebra.ones(div(1024^3, 8)) for …

---

## [Circular reference crash when reading fasta file](https://discourse.julialang.org/t/circular-reference-crash-when-reading-fasta-file/34126)

<div class="topic-metadata">

**Author:** [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Replies:** 1\
**Last updated:** [February 3, 2020, 4:18pm UTC](https://discourse.julialang.org/t/circular-reference-crash-when-reading-fasta-file/34126 "2020-02-03T16:18:41Z")

</div>

I have this piece of code : function load\_genome(genome\_path, haschr=true) genome\_index = string(genome\_path,".fai") f = open(genome\_path) reader = BioSequences.FASTA.Reader(f; index=genome\_index) genom…

---

## [Adding documentation string in metaprogramming function definition eval loop](https://discourse.julialang.org/t/adding-documentation-string-in-metaprogramming-function-definition-eval-loop/34156)

<div class="topic-metadata">

**Author:** [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Replies:** 3\
**Last updated:** [February 4, 2020, 10:50am UTC](https://discourse.julialang.org/t/adding-documentation-string-in-metaprogramming-function-definition-eval-loop/34156 "2020-02-04T10:50:20Z")

</div>

I have this nice codeblock: for (dim, Dim) in (("time", :Time), ("zonal", :Lon)) @eval begin # """ # $(dim)average(a::DimensionalArray, i=end) # Return the $(dim)-averaged \`a\` (average ac…

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

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