# General Usage

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

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

**Page:** 847

---

## [How to force single column array?](https://discourse.julialang.org/t/how-to-force-single-column-array/26746)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 31\
**Last updated:** [July 25, 2019, 9:28pm UTC](https://discourse.julialang.org/t/how-to-force-single-column-array/26746 "2019-07-25T21:28:28Z")

</div>

Hey guys, I want to make an array with only a single column, so ie. something like 4x1 Array{Int32,1} Whenever I use zeros or undef I get like this: zeros(Int32,4,1) 4×1 Array{Int32,2}: 0 0 0 0 Can I force the out…

---

## [Possible Issue? Performance making tuples from vectors](https://discourse.julialang.org/t/possible-issue-performance-making-tuples-from-vectors/26809)

<div class="topic-metadata">

**Author:** [@clinton](https://discourse.julialang.org/u/clinton)\
**Replies:** 0\
**Last updated:** [July 25, 2019, 8:08pm UTC](https://discourse.julialang.org/t/possible-issue-performance-making-tuples-from-vectors/26809 "2019-07-25T20:08:06Z")

</div>

I am posting this here first since it seems very similar to #32673, including that it only seems to affect compile time. Happy to file an issue though. Switching to any union type makes performance far worse (as in (O(N…

---

## [Convert all strings in a DataFrame to upper case in the most performant way possible](https://discourse.julialang.org/t/convert-all-strings-in-a-dataframe-to-upper-case-in-the-most-performant-way-possible/26794)

<div class="topic-metadata">

**Author:** [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Replies:** 9\
**Last updated:** [July 25, 2019, 5:24pm UTC](https://discourse.julialang.org/t/convert-all-strings-in-a-dataframe-to-upper-case-in-the-most-performant-way-possible/26794 "2019-07-25T17:24:07Z")

</div>

Converting all strings to either upper- or lower-case is a common task in data prep/cleaning. Currently, I do this as follows: function uppercase\_strings(df::DataFrame) for row in eachrow(describe(df)) if ro…

---

## [How do you structure your code?](https://discourse.julialang.org/t/how-do-you-structure-your-code/26566)

<div class="topic-metadata">

**Author:** [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Replies:** 12\
**Last updated:** [July 25, 2019, 5:03pm UTC](https://discourse.julialang.org/t/how-do-you-structure-your-code/26566 "2019-07-25T17:03:42Z")

</div>

I’m defining N types and let’s say there are 5-15 functions for each types. How would you structure your code? Each file contains a single type and related definitions One file contains all types, and a separate file …

---

## [Subtypes or parametric types to define constructor-dependent functions](https://discourse.julialang.org/t/subtypes-or-parametric-types-to-define-constructor-dependent-functions/26681)

<div class="topic-metadata">

**Author:** [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Replies:** 6\
**Last updated:** [July 25, 2019, 3:23pm UTC](https://discourse.julialang.org/t/subtypes-or-parametric-types-to-define-constructor-dependent-functions/26681 "2019-07-25T15:23:53Z")

</div>

I have a structure of data that can be returned by two (or more) different functions, such as: struct MyType x::Int end f1(x) = MyType(x) f2(x, y) = MyType(x - y) Now, I want another function g to take such object…

---

## [What is the best way to generate a function based on the other function definition?](https://discourse.julialang.org/t/what-is-the-best-way-to-generate-a-function-based-on-the-other-function-definition/26748)

<div class="topic-metadata">

**Author:** [@raff](https://discourse.julialang.org/u/raff)\
**Replies:** 5\
**Last updated:** [July 25, 2019, 2:00pm UTC](https://discourse.julialang.org/t/what-is-the-best-way-to-generate-a-function-based-on-the-other-function-definition/26748 "2019-07-25T14:00:59Z")

</div>

Let’s say I have a function function compute(x::Vector, y::Vector) return (x' \* y) / sum(y) end Both x and y are vector with 0 or 1 values on each cell. Based on this definition, I want to automatically generate …

---

## [Lazy Loading of Modules](https://discourse.julialang.org/t/lazy-loading-of-modules/26788)

<div class="topic-metadata">

**Author:** [@cortner](https://discourse.julialang.org/u/cortner)\
**Replies:** 0\
**Last updated:** [July 25, 2019, 11:21am UTC](https://discourse.julialang.org/t/lazy-loading-of-modules/26788 "2019-07-25T11:21:45Z")

</div>

This question essentially revives this older topic. I dislike long loading times for modules that I use fairly interactively. Let’s say I have a module A, and a single (or very few) function fB in A depends on another m…

---

## [How to access shared "inherited" fields without paying multiple dispatch performance price?](https://discourse.julialang.org/t/how-to-access-shared-inherited-fields-without-paying-multiple-dispatch-performance-price/26762)

<div class="topic-metadata">

**Author:** [@Russ](https://discourse.julialang.org/u/Russ)\
**Replies:** 14\
**Last updated:** [July 25, 2019, 9:46am UTC](https://discourse.julialang.org/t/how-to-access-shared-inherited-fields-without-paying-multiple-dispatch-performance-price/26762 "2019-07-25T09:46:23Z")

</div>

Hi, I’m evaluating Julia to replace some old C++ code. The code uses inheritance where there is a single base class and lots (100’s) of derived classes. There are a large number of instances, and the code needs to be abl…

---

## [Loading modules on remote workers in Julia 1.0/.7](https://discourse.julialang.org/t/loading-modules-on-remote-workers-in-julia-1-0-7/13312)

<div class="topic-metadata">

**Author:** [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Replies:** 7\
**Last updated:** [July 25, 2019, 8:51am UTC](https://discourse.julialang.org/t/loading-modules-on-remote-workers-in-julia-1-0-7/13312 "2019-07-25T08:51:15Z")

</div>

I’m having difficulty loading a module on remote workers. Suppose I have a file called myModule.jl in a directory assigned to variable called path. In the past, I simply added path to LOAD\_PATH and entered @everywhere us…

---

## [Recursive for loop to create data frame](https://discourse.julialang.org/t/recursive-for-loop-to-create-data-frame/26747)

<div class="topic-metadata">

**Author:** [@gobs](https://discourse.julialang.org/u/gobs)\
**Replies:** 3\
**Last updated:** [July 25, 2019, 8:14am UTC](https://discourse.julialang.org/t/recursive-for-loop-to-create-data-frame/26747 "2019-07-25T08:14:30Z")

</div>

I have some JuMP (optimisation package) variables which I want to save to a data frame to then save to a .csv file. My idea is to have a data frame that would look something like this: df = DataFrame(JuMPVariable = Symb…

---

## [Distributed versions of mapslice](https://discourse.julialang.org/t/distributed-versions-of-mapslice/26783)

<div class="topic-metadata">

**Author:** [@Charlie\_He](https://discourse.julialang.org/u/Charlie_He)\
**Replies:** 1\
**Last updated:** [July 25, 2019, 7:51am UTC](https://discourse.julialang.org/t/distributed-versions-of-mapslice/26783 "2019-07-25T07:51:35Z")

</div>

I found julia awfully lacking in terms of operations among/along specific axis/axes of matrix/tensors. It has been extremely annoying that there is no “dims” argument for sum, reduce, mean, prod, etc… The only option for…

---

## [Why doesn't this code work? Related to Tuples and Types](https://discourse.julialang.org/t/why-doesnt-this-code-work-related-to-tuples-and-types/26772)

<div class="topic-metadata">

**Author:** [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Replies:** 3\
**Last updated:** [July 25, 2019, 6:03am UTC](https://discourse.julialang.org/t/why-doesnt-this-code-work-related-to-tuples-and-types/26772 "2019-07-25T06:03:54Z")

</div>

Here is an example: mm(::Type{Tuple{X,Y}}) where X where Y = Type\[X,Y\] julia\> mm(Tuple{Int,T} where T\<:Float64) ERROR: UndefVarError: Y not defined Stacktrace: \[1\] mm(::Type{Tuple{Int64,T} where T\<:Float64}) at ./none:…

---

## [Function Signature & Keyword arguments](https://discourse.julialang.org/t/function-signature-keyword-arguments/26771)

<div class="topic-metadata">

**Author:** [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Replies:** 0\
**Last updated:** [July 25, 2019, 2:34am UTC](https://discourse.julialang.org/t/function-signature-keyword-arguments/26771 "2019-07-25T02:34:54Z")

</div>

Hi, I have a question, why can’t we access the keyword variables in the signature of a method? Here is an example; f(x::Int,y::T;z::U = 4) where T\<:U where U\<:Real = begin println("Z : ",typeof(z)) …

---

## [A way to get the latest method of a function?](https://discourse.julialang.org/t/a-way-to-get-the-latest-method-of-a-function/26766)

<div class="topic-metadata">

**Author:** [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Replies:** 3\
**Last updated:** [July 25, 2019, 1:45am UTC](https://discourse.julialang.org/t/a-way-to-get-the-latest-method-of-a-function/26766 "2019-07-25T01:45:05Z")

</div>

Hi, everyone. Example: f(x::Int) = x+1 mt = get\_latest\_method(f) # mt -\> function f with signature Int f(x::Float64) = x\*2.0 mt = get\_latest\_method(f) # mt -\> function f with signature Float64 f(x::Int,y::Float64) = x…

---

## [System error loading custom package](https://discourse.julialang.org/t/system-error-loading-custom-package/26765)

<div class="topic-metadata">

**Author:** [@Tims\_Corbett](https://discourse.julialang.org/u/Tims_Corbett)\
**Replies:** 0\
**Last updated:** [July 25, 2019, 12:39am UTC](https://discourse.julialang.org/t/system-error-loading-custom-package/26765 "2019-07-25T00:39:02Z")

</div>

Custom is a user defined package. It is present in the directory below. From REPL, using Custom works. A script that uses it also works. If another script uses it at the same time, the following error is encountered. Sy…

---

## [Speeding up matrix multiplication with a subset of matrix's rows](https://discourse.julialang.org/t/speeding-up-matrix-multiplication-with-a-subset-of-matrixs-rows/26718)

<div class="topic-metadata">

**Author:** [@kernelmethod](https://discourse.julialang.org/u/kernelmethod)\
**Replies:** 12\
**Last updated:** [July 24, 2019, 11:23pm UTC](https://discourse.julialang.org/t/speeding-up-matrix-multiplication-with-a-subset-of-matrixs-rows/26718 "2019-07-24T23:23:52Z")

</div>

Hi all, Pretty straightforward – I’d like to write some code that performs a matvec between a matrix A and a vector x, except I know ahead of time that I don’t need all of the rows of A. In other words, instead of perf…

---

## [List of what actions can cause a task switch?](https://discourse.julialang.org/t/list-of-what-actions-can-cause-a-task-switch/26751)

<div class="topic-metadata">

**Author:** [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Replies:** 2\
**Last updated:** [July 24, 2019, 6:27pm UTC](https://discourse.julialang.org/t/list-of-what-actions-can-cause-a-task-switch/26751 "2019-07-24T18:27:21Z")

</div>

What I wanted to do was run multiple external commands simultaneously and collect the results…so my first thought was to use Distributed creating N workers and have them execute the commands and return the data via a Rem…

---

## [CuArrays.jl errors with indexing / CartesianIndices](https://discourse.julialang.org/t/cuarrays-jl-errors-with-indexing-cartesianindices/26416)

<div class="topic-metadata">

**Author:** [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Replies:** 1\
**Last updated:** [July 24, 2019, 5:18pm UTC](https://discourse.julialang.org/t/cuarrays-jl-errors-with-indexing-cartesianindices/26416 "2019-07-24T17:18:31Z")

</div>

Hi, I need to record the range of a subarray in a struct in order to define a padded-array. However I have troubles using indexing in CuArrays.jl. Basically, the only solution which works is to use things like u\[1:10,1…

---

## [Is spzeros(m,n) empty?](https://discourse.julialang.org/t/is-spzeros-m-n-empty/26733)

<div class="topic-metadata">

**Author:** [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Replies:** 3\
**Last updated:** [July 24, 2019, 4:31pm UTC](https://discourse.julialang.org/t/is-spzeros-m-n-empty/26733 "2019-07-24T16:31:29Z")

</div>

Based on my understanding, spzeros(m,n) would create a sparse matrix of zeros with size m\*n. I checked and found that calling isempty with a matrix like this would return false. What I do not understand is that, based on…

---

## [Time to first plot benchmark](https://discourse.julialang.org/t/time-to-first-plot-benchmark/26726)

<div class="topic-metadata">

**Author:** [@jling](https://discourse.julialang.org/u/jling)\
**Replies:** 11\
**Last updated:** [July 24, 2019, 3:42pm UTC](https://discourse.julialang.org/t/time-to-first-plot-benchmark/26726 "2019-07-24T15:42:55Z")

</div>

In the light of Julia survey result (i.e people complain about time to the first plot), I did a naive benchmark, as expected, PyPlot is the fastest :frowning: http://uaf-8.t2.ucsd.edu/~jling/dump/PlotBenchmark.html Bec…

---

## [Help reshaping this array more efficiently](https://discourse.julialang.org/t/help-reshaping-this-array-more-efficiently/26724)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 6\
**Last updated:** [July 24, 2019, 2:34pm UTC](https://discourse.julialang.org/t/help-reshaping-this-array-more-efficiently/26724 "2019-07-24T14:34:41Z")

</div>

Hey guys, so I got an array like this: a\[1\] 15300-element Array{Float32,1}: 0.0 0.0 0.0 0.0 0.0 0.1 0.0 0.0 0.2 0.1 0.0 0.0 0.2 ⋮ 9.6 0.0 4.9 9.7 0.0 4.9 9.8 0.0 4.9 9.9 0.0 4.9 Where the fir…

---

## [SparseMatrixCSC in Julia?](https://discourse.julialang.org/t/sparsematrixcsc-in-julia/26731)

<div class="topic-metadata">

**Author:** [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Replies:** 1\
**Last updated:** [July 24, 2019, 12:10pm UTC](https://discourse.julialang.org/t/sparsematrixcsc-in-julia/26731 "2019-07-24T12:10:07Z")

</div>

Hi, I’m curious about this SparseMatrixCSC object in Julia. The following is the constructor. I was wondering, how to understand that “The row indices in every column need to be sorted. If your SparseMatrixCSC object co…

---

## [Recompiles and failures to load JLD2 in Atom/Juno](https://discourse.julialang.org/t/recompiles-and-failures-to-load-jld2-in-atom-juno/26734)

<div class="topic-metadata">

**Author:** [@FHell](https://discourse.julialang.org/u/FHell)\
**Replies:** 0\
**Last updated:** [July 24, 2019, 12:06pm UTC](https://discourse.julialang.org/t/recompiles-and-failures-to-load-jld2-in-atom-juno/26734 "2019-07-24T12:06:24Z")

</div>

I have a problem with a script that loads a JLD2 file. When I run it from bash it works fine, but if I run it block by block in Juno first of all I get constant recompiles due to stale cache files (which frequently fail)…

---

## [Zygote gradient](https://discourse.julialang.org/t/zygote-gradient/26715)

<div class="topic-metadata">

**Author:** [@wormholestds9](https://discourse.julialang.org/u/wormholestds9)\
**Replies:** 2\
**Last updated:** [July 24, 2019, 9:58am UTC](https://discourse.julialang.org/t/zygote-gradient/26715 "2019-07-24T09:58:14Z")

</div>

Zygote gradient seems to return an odd result for a constant function. That is, f1 = (x) → 0.0 gradient(f1,0) = (nothing,) but f2 = (x) → x^2 gradient(f2, 0) = (0,) Why does the first one return “nothing” instead o…

---

## [Pkg Manager Problems after an update](https://discourse.julialang.org/t/pkg-manager-problems-after-an-update/26704)

<div class="topic-metadata">

**Author:** [@cortner](https://discourse.julialang.org/u/cortner)\
**Replies:** 8\
**Last updated:** [July 24, 2019, 4:56am UTC](https://discourse.julialang.org/t/pkg-manager-problems-after-an-update/26704 "2019-07-24T04:56:26Z")

</div>

I’ve recently tagged new versions of two of my packages, JuLIP.jl and NeighbourLists.jl, and all hell has broken loose now in my small package eco-system. I would be grateful for any help in unravelling this. I performed…

---

## [Using LabelledArrays with ArrayPartition](https://discourse.julialang.org/t/using-labelledarrays-with-arraypartition/26707)

<div class="topic-metadata">

**Author:** [@mzilhao](https://discourse.julialang.org/u/mzilhao)\
**Replies:** 1\
**Last updated:** [July 24, 2019, 2:35am UTC](https://discourse.julialang.org/t/using-labelledarrays-with-arraypartition/26707 "2019-07-24T02:35:24Z")

</div>

I was wondering if there is any way of using the functionality of LabelledArrays.jl with ArrayPartition. I’m finding ArrayPartition very convenient to group together and pass around arrays storing different variables (w…

---

## [Most idomatic way to convert an Images.jl Image to a 3-d array?](https://discourse.julialang.org/t/most-idomatic-way-to-convert-an-images-jl-image-to-a-3-d-array/7104)

<div class="topic-metadata">

**Author:** [@mac01021](https://discourse.julialang.org/u/mac01021)\
**Replies:** 6\
**Last updated:** [July 23, 2019, 11:03pm UTC](https://discourse.julialang.org/t/most-idomatic-way-to-convert-an-images-jl-image-to-a-3-d-array/7104 "2019-07-23T23:03:54Z")

</div>

I’ve loaded an image file to get a 2-d array of RGB color values. What I want is a 3-d array with depth 3. The function below will do the job. But is there a more idomatic way? rgb\_to\_array(img) = begin H, W = h…

---

## [CI/testing for big endian architectures?](https://discourse.julialang.org/t/ci-testing-for-big-endian-architectures/26671)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 6\
**Last updated:** [July 23, 2019, 6:58pm UTC](https://discourse.julialang.org/t/ci-testing-for-big-endian-architectures/26671 "2019-07-23T18:58:15Z")

</div>

I am working on code for which byte order is relevant when unpacking binary data. My understanding is that most modern architectures are little-endian, so I could just put an Base.ENDIAN\_BOM == 0x04030201 || error("only…

---

## [How to use SIMD with a very simple example](https://discourse.julialang.org/t/how-to-use-simd-with-a-very-simple-example/26676)

<div class="topic-metadata">

**Author:** [@davidbp](https://discourse.julialang.org/u/davidbp)\
**Replies:** 6\
**Last updated:** [July 23, 2019, 5:05pm UTC](https://discourse.julialang.org/t/how-to-use-simd-with-a-very-simple-example/26676 "2019-07-23T17:05:53Z")

</div>

Hello, I am trying to understand how to use SIMD.jl. After trying the vadd! example in the documentation I wanted use SIMD in a different example. No success so far. This is what I would like to simdify: function myf…

---

## [How to get second order gradient of a neural network?](https://discourse.julialang.org/t/how-to-get-second-order-gradient-of-a-neural-network/26631)

<div class="topic-metadata">

**Author:** [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)\
**Replies:** 1\
**Last updated:** [July 23, 2019, 12:53pm UTC](https://discourse.julialang.org/t/how-to-get-second-order-gradient-of-a-neural-network/26631 "2019-07-23T12:53:10Z")

</div>

Hi, I am trying to plot the second order derivative of a single input-single output neural network. I can do the first order derivative just fine but the second order derivative computed with the Tracker package is simp…

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

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