# General Usage

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

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

**Page:** 525

---

## [How to construct a large sparse matrix?](https://discourse.julialang.org/t/how-to-construct-a-large-sparse-matrix/7241)

<div class="topic-metadata">

**Author:** [@onetonfoot](https://discourse.julialang.org/u/onetonfoot)\
**Replies:** 6\
**Last updated:** [November 4, 2021, 4:58pm UTC](https://discourse.julialang.org/t/how-to-construct-a-large-sparse-matrix/7241 "2021-11-04T16:58:20Z")

</div>

Currently, I’m using n = 10^5 M = sparse(BitArray(n,n)) But when n \> 10^6 I run out of memory so this doesn’t work. I’m unsure what to do as the bellow syntax chucks an error SparseMatrixCSC{Bool}(n,n) MethodError: no…

---

## [PyError pyeval.jl not found](https://discourse.julialang.org/t/pyerror-pyeval-jl-not-found/70813)

<div class="topic-metadata">

**Author:** [@max\_schwarzer](https://discourse.julialang.org/u/max_schwarzer)\
**Replies:** 2\
**Last updated:** [November 4, 2021, 4:29pm UTC](https://discourse.julialang.org/t/pyerror-pyeval-jl-not-found/70813 "2021-11-04T16:29:38Z")

</div>

I am using Anaconda and when trying to use PyCall in Julia I get the following error: ERROR: PyError ($(Expr(:escape, :(ccall(#= C:\\Users\\mschwarz.julia\\packages\\PyCall\\BD546\\src\\pyeval.jl:38 =# @pysym(:PyEval\_EvalCode…

---

## [How to use the Windows API for Desktop Duplication API?](https://discourse.julialang.org/t/how-to-use-the-windows-api-for-desktop-duplication-api/70962)

<div class="topic-metadata">

**Author:** [@Pytrator](https://discourse.julialang.org/u/Pytrator)\
**Replies:** 0\
**Last updated:** [November 4, 2021, 3:50pm UTC](https://discourse.julialang.org/t/how-to-use-the-windows-api-for-desktop-duplication-api/70962 "2021-11-04T15:50:32Z")

</div>

Hey there! I try to get as many frames of my desktop as possible. The Windows desktop API appears to be a good solution to get that. However, I don’t know how to do it. I now get things done when it’s documented for C …

---

## [Simple type problem](https://discourse.julialang.org/t/simple-type-problem/70958)

<div class="topic-metadata">

**Author:** [@Igor\_Douven](https://discourse.julialang.org/u/Igor_Douven)\
**Replies:** 2\
**Last updated:** [November 4, 2021, 3:07pm UTC](https://discourse.julialang.org/t/simple-type-problem/70958 "2021-11-04T15:07:08Z")

</div>

I have an abstract type, abstract type AT end and two mutable structs that are subtypes of AT: mutable struct S1 \<: AT #something end mutable struct S2 \<: AT #something end I would like to define a function …

---

## [Multithreading problem](https://discourse.julialang.org/t/multithreading-problem/70357)

<div class="topic-metadata">

**Author:** [@Jake](https://discourse.julialang.org/u/Jake)\
**Replies:** 10\
**Last updated:** [November 4, 2021, 12:03pm UTC](https://discourse.julialang.org/t/multithreading-problem/70357 "2021-11-04T12:03:13Z")

</div>

This is my first time trying to use multithreading for real work. I have an inner loop in my code for doing sinc interpolation of a recorded time history file. A minimum working example is # Minumum working example fo…

---

## [Always display the methods definition when displaying the documentation](https://discourse.julialang.org/t/always-display-the-methods-definition-when-displaying-the-documentation/70921)

<div class="topic-metadata">

**Author:** [@tencnivel](https://discourse.julialang.org/u/tencnivel)\
**Replies:** 1\
**Last updated:** [November 4, 2021, 10:06am UTC](https://discourse.julialang.org/t/always-display-the-methods-definition-when-displaying-the-documentation/70921 "2021-11-04T10:06:26Z")

</div>

By default, if a function has a docstring, only the content of the docstring is displayed. I would like to always have the description of the methods when displaying the documentation of a function. In the way that Juno…

---

## [Alternative to very time-consuming array operations](https://discourse.julialang.org/t/alternative-to-very-time-consuming-array-operations/70620)

<div class="topic-metadata">

**Author:** [@anneJulia](https://discourse.julialang.org/u/anneJulia)\
**Replies:** 9\
**Last updated:** [November 4, 2021, 8:44am UTC](https://discourse.julialang.org/t/alternative-to-very-time-consuming-array-operations/70620 "2021-11-04T08:44:24Z")

</div>

I am writing a function where array operations, such as the example below, have to happen a few hundred thousand times. arr = \[1,0,0,1,1\] idx = \[2,4\] res = arr\[idx\] When using a profiler to analyse the code 89.69% of …

---

## [Get distances of many points within a max range, any performance improvements?](https://discourse.julialang.org/t/get-distances-of-many-points-within-a-max-range-any-performance-improvements/70917)

<div class="topic-metadata">

**Author:** [@Jon\_Norberg](https://discourse.julialang.org/u/Jon_Norberg)\
**Replies:** 8\
**Last updated:** [November 3, 2021, 11:56pm UTC](https://discourse.julialang.org/t/get-distances-of-many-points-within-a-max-range-any-performance-improvements/70917 "2021-11-03T23:56:23Z")

</div>

I have a potentially very long (N) set of points W with three dimensions. I need to make distance based calculations between all points within a set max distance. Below is my best attempt so far. Any performance improvem…

---

## [CSV.jl number of lines](https://discourse.julialang.org/t/csv-jl-number-of-lines/70785)

<div class="topic-metadata">

**Author:** [@Michal](https://discourse.julialang.org/u/Michal)\
**Replies:** 13\
**Last updated:** [November 3, 2021, 9:36pm UTC](https://discourse.julialang.org/t/csv-jl-number-of-lines/70785 "2021-11-03T21:36:53Z")

</div>

I cannot use attribute “resusebuffer” in latest version of CSV.jl package. How can I calculate exact number of lines in CSV? function countcsvlines(file) n = 0 for row in CSV.Rows(file; resusebuffer=true) …

---

## [Julia indexing question](https://discourse.julialang.org/t/julia-indexing-question/70911)

<div class="topic-metadata">

**Author:** [@leon](https://discourse.julialang.org/u/leon)\
**Replies:** 1\
**Last updated:** [November 3, 2021, 8:54pm UTC](https://discourse.julialang.org/t/julia-indexing-question/70911 "2021-11-03T20:54:54Z")

</div>

I have a matrix as below: A = \[1 2 3; 4 5 6\]; I need to find the index of those that meet these requirements Ind = map(A) do a (a \> 4) || (a \<3); end Here are the results: 2×3 Matrix{Bool}: 1 1 0 0 1 1 Ev…

---

## [Not possible connecting julia to atom](https://discourse.julialang.org/t/not-possible-connecting-julia-to-atom/70908)

<div class="topic-metadata">

**Author:** [@Louise](https://discourse.julialang.org/u/Louise)\
**Replies:** 3\
**Last updated:** [November 3, 2021, 8:22pm UTC](https://discourse.julialang.org/t/not-possible-connecting-julia-to-atom/70908 "2021-11-03T20:22:36Z")

</div>

Hey everyone! I installed Atom including all the relevant packages but i can’t connect it to Julia (julia itself works perfectly fine). I can’t even type anything into the REPL on Atom (there is a sad smiley - a screens…

---

## [Improving Performance of a Loop](https://discourse.julialang.org/t/improving-performance-of-a-loop/70905)

<div class="topic-metadata">

**Author:** [@jmcastro2109](https://discourse.julialang.org/u/jmcastro2109)\
**Replies:** 9\
**Last updated:** [November 3, 2021, 8:12pm UTC](https://discourse.julialang.org/t/improving-performance-of-a-loop/70905 "2021-11-03T20:12:57Z")

</div>

Hi! I am trying to make the following function faster. Any suggestion would be very much appreciated. using Random using LinearAlgebra using BenchmarkTools ############################################################…

---

## [How to return the line that contains specific information from a file?](https://discourse.julialang.org/t/how-to-return-the-line-that-contains-specific-information-from-a-file/70889)

<div class="topic-metadata">

**Author:** [@Amro](https://discourse.julialang.org/u/Amro)\
**Replies:** 7\
**Last updated:** [November 3, 2021, 8:03pm UTC](https://discourse.julialang.org/t/how-to-return-the-line-that-contains-specific-information-from-a-file/70889 "2021-11-03T20:03:30Z")

</div>

I have a read file (lets say eventually its name S and has the below data). How to return the locations (line and position in the line) that contains Hi world? #filehandle = open("$file"); #S = readlines(filehandle); #c…

---

## [Why is a, b = rand(2) so bad?](https://discourse.julialang.org/t/why-is-a-b-rand-2-so-bad/70859)

<div class="topic-metadata">

**Author:** [@rakeshvar](https://discourse.julialang.org/u/rakeshvar)\
**Replies:** 9\
**Last updated:** [November 3, 2021, 5:46pm UTC](https://discourse.julialang.org/t/why-is-a-b-rand-2-so-bad/70859 "2021-11-03T17:46:10Z")

</div>

I am trying to find the Expected Value of maximum of two U\[0, 1\] RVs. Why is a call to rand(2) so much worse than two to rand(), rand()? julia\> function h(N) s = 0. for \_ in 1:N a, b…

---

## [Error message prints entire dataframe](https://discourse.julialang.org/t/error-message-prints-entire-dataframe/70883)

<div class="topic-metadata">

**Author:** [@k10](https://discourse.julialang.org/u/k10)\
**Replies:** 5\
**Last updated:** [November 3, 2021, 5:26pm UTC](https://discourse.julialang.org/t/error-message-prints-entire-dataframe/70883 "2021-11-03T17:26:12Z")

</div>

I encounter an error when i improperly attempt to use the length() function on a dataframe. The error message ends up printing the entire dataframe like so: Error: MethodError(length, (5189×16 DataFrame and then it pr…

---

## [Assigning values in for loop allocates memory](https://discourse.julialang.org/t/assigning-values-in-for-loop-allocates-memory/70851)

<div class="topic-metadata">

**Author:** [@Mikhail\_Kagalenko](https://discourse.julialang.org/u/Mikhail_Kagalenko)\
**Replies:** 3\
**Last updated:** [November 3, 2021, 5:00pm UTC](https://discourse.julialang.org/t/assigning-values-in-for-loop-allocates-memory/70851 "2021-11-03T17:00:28Z")

</div>

Why would that loop allocate anything at all? julia\> (M, N) = (512, 2048) A=zeros(M, N) v=zeros(M) @btime for k in 1:N v .= randn() A\[:, k\] = v end 2.502 ms (10756 allocat…

---

## [TimerOutputs and --track-allocation=user](https://discourse.julialang.org/t/timeroutputs-and-track-allocation-user/70884)

<div class="topic-metadata">

**Author:** [@Niceno](https://discourse.julialang.org/u/Niceno)\
**Replies:** 0\
**Last updated:** [November 3, 2021, 3:31pm UTC](https://discourse.julialang.org/t/timeroutputs-and-track-allocation-user/70884 "2021-11-03T15:31:15Z")

</div>

Dear all, I use TimerOutputs in my Julia code for profiling, but when I also want to check memory with --track-allocation=user option on start up, all the output is condensed in one line, the one with @timeit macro at t…

---

## [Sparse DataFrame](https://discourse.julialang.org/t/sparse-dataframe/64096)

<div class="topic-metadata">

**Author:** [@alexlenail](https://discourse.julialang.org/u/alexlenail)\
**Replies:** 9\
**Last updated:** [November 3, 2021, 1:39pm UTC](https://discourse.julialang.org/t/sparse-dataframe/64096 "2021-11-03T13:39:07Z")

</div>

DataFrame(sparse\_matrix) gives me: ArgumentError: a 'SparseMatrixCSC{Float64,Int64}' is not a table; see \`?Tables.table\` for ways to treat an AbstractMatrix as a table I can’t find documentation about how to load a spa…

---

## [Is Julia compatible with Mac OS Monterey?](https://discourse.julialang.org/t/is-julia-compatible-with-mac-os-monterey/70588)

<div class="topic-metadata">

**Author:** [@leon](https://discourse.julialang.org/u/leon)\
**Replies:** 13\
**Last updated:** [November 3, 2021, 1:04pm UTC](https://discourse.julialang.org/t/is-julia-compatible-with-mac-os-monterey/70588 "2021-11-03T13:04:29Z")

</div>

I plan to upgrade my operating system to the latest Mac OS Monterey. Anyone knows if Julia is compatible with it? Many thanks.

---

## [How to check if my gridded X and Y are inside a polygon?](https://discourse.julialang.org/t/how-to-check-if-my-gridded-x-and-y-are-inside-a-polygon/70728)

<div class="topic-metadata">

**Author:** [@leon](https://discourse.julialang.org/u/leon)\
**Replies:** 25\
**Last updated:** [November 3, 2021, 12:52pm UTC](https://discourse.julialang.org/t/how-to-check-if-my-gridded-x-and-y-are-inside-a-polygon/70728 "2021-11-03T12:52:08Z")

</div>

I have gridded X and Y that are defined by lon = 20:0.25:379.75; lat = -90:0.25:89.75; X, Y = ndgrid(lon, lat). My goal is to create a Boolean array (named Index) the same size as X (or Y) and their values should be …

---

## [Segfault when using promote\_typejoin to control small union behaviour over parametric type](https://discourse.julialang.org/t/segfault-when-using-promote-typejoin-to-control-small-union-behaviour-over-parametric-type/23666)

<div class="topic-metadata">

**Author:** [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Replies:** 0\
**Last updated:** [April 29, 2019, 7:54pm UTC](https://discourse.julialang.org/t/segfault-when-using-promote-typejoin-to-control-small-union-behaviour-over-parametric-type/23666 "2019-04-29T19:54:20Z")

</div>

I have a parametric type AtLeast{T}(x::T), and I’d like my broadcasts over vectors of Union{Float64, AtLeast} to propagate its type, instead of becoming Any. Following the discussion in this post, I do this: julia\> stru…

---

## [Search engines may redirect to old version of package documentation](https://discourse.julialang.org/t/search-engines-may-redirect-to-old-version-of-package-documentation/70862)

<div class="topic-metadata">

**Author:** [@DorianT](https://discourse.julialang.org/u/DorianT)\
**Replies:** 1\
**Last updated:** [November 3, 2021, 10:36am UTC](https://discourse.julialang.org/t/search-engines-may-redirect-to-old-version-of-package-documentation/70862 "2021-11-03T10:36:32Z")

</div>

Over the past 6 or so month while learning Julia bit by bit, I noticed that many times when I use a search engine of my choice to look for some documentation on a package, I end up on a rather outdated documentation, mak…

---

## [Stacked bar chart with both positive and negative values](https://discourse.julialang.org/t/stacked-bar-chart-with-both-positive-and-negative-values/70852)

<div class="topic-metadata">

**Author:** [@IljaK91](https://discourse.julialang.org/u/IljaK91)\
**Replies:** 3\
**Last updated:** [November 3, 2021, 10:16am UTC](https://discourse.julialang.org/t/stacked-bar-chart-with-both-positive-and-negative-values/70852 "2021-11-03T10:16:09Z")

</div>

Hey everyone, I was looking for how to create a specific plot with stacked bars that have both positive and negative values. That is the plot that I am trying to recreate: Does anybody have a suggestion on how to go…

---

## [Stuck with another allocation question](https://discourse.julialang.org/t/stuck-with-another-allocation-question/70850)

<div class="topic-metadata">

**Author:** [@goerch](https://discourse.julialang.org/u/goerch)\
**Replies:** 2\
**Last updated:** [November 3, 2021, 8:46am UTC](https://discourse.julialang.org/t/stuck-with-another-allocation-question/70850 "2021-11-03T08:46:20Z")

</div>

The following program using BenchmarkTools const Example1 = Tuple{Int, Float64, Float64, Float64} const Example2 = Tuple{Int, Float64} function init!(v, n) for i in 1:n push!(v, (i, rand(), rand(), rand())…

---

## [Help with \`try\`ing different algorithms for root solving](https://discourse.julialang.org/t/help-with-try-ing-different-algorithms-for-root-solving/70832)

<div class="topic-metadata">

**Author:** [@amrods](https://discourse.julialang.org/u/amrods)\
**Replies:** 14\
**Last updated:** [November 3, 2021, 1:54am UTC](https://discourse.julialang.org/t/help-with-try-ing-different-algorithms-for-root-solving/70832 "2021-11-03T01:54:07Z")

</div>

I am trying to program a function that tries different root-finding algorithms depending on whether they succeed or not. How can I accomplish that? I programmed a prototype below, but it does not seem to work: using Roo…

---

## [How to test if one float is an integer multiple of another?](https://discourse.julialang.org/t/how-to-test-if-one-float-is-an-integer-multiple-of-another/70745)

<div class="topic-metadata">

**Author:** [@jewh](https://discourse.julialang.org/u/jewh)\
**Replies:** 9\
**Last updated:** [November 2, 2021, 10:09pm UTC](https://discourse.julialang.org/t/how-to-test-if-one-float-is-an-integer-multiple-of-another/70745 "2021-11-02T22:09:36Z")

</div>

What is the best way to test if one floating point number is an integer multiple of another floating number? e.g. I want this to return true for 5.5 / 0.5, and false for 5.5 / 0.6. Naively I would expect to do this by t…

---

## [Trying to understand broadcast better](https://discourse.julialang.org/t/trying-to-understand-broadcast-better/70778)

<div class="topic-metadata">

**Author:** [@joshdpark](https://discourse.julialang.org/u/joshdpark)\
**Replies:** 9\
**Last updated:** [November 2, 2021, 9:35pm UTC](https://discourse.julialang.org/t/trying-to-understand-broadcast-better/70778 "2021-11-02T21:35:32Z")

</div>

Having a list of 2x1 vectors, I wanted to do a for loop for the array and hcat each element with each vector to create a 2x2 matrix. I was able to get what I wanted with a list comprehension but I was wondering if there’…

---

## [\`Makie.convert\_arguments\` example](https://discourse.julialang.org/t/makie-convert-arguments-example/70823)

<div class="topic-metadata">

**Author:** [@OvidiusCicero](https://discourse.julialang.org/u/OvidiusCicero)\
**Replies:** 3\
**Last updated:** [November 2, 2021, 9:06pm UTC](https://discourse.julialang.org/t/makie-convert-arguments-example/70823 "2021-11-02T21:06:22Z")

</div>

I found this https://makie.juliaplots.org/stable/documentation/recipes/ but I’m not able to able to follow it to be honest. For example, let’s have a struct struct A val::Float32 end which I want to plot by using…

---

## [Too new for this world problem when called from a function](https://discourse.julialang.org/t/too-new-for-this-world-problem-when-called-from-a-function/70820)

<div class="topic-metadata">

**Author:** [@Niceno](https://discourse.julialang.org/u/Niceno)\
**Replies:** 14\
**Last updated:** [November 2, 2021, 8:54pm UTC](https://discourse.julialang.org/t/too-new-for-this-world-problem-when-called-from-a-function/70820 "2021-11-02T20:54:16Z")

</div>

Dear all, As a part of a program I am developing in Julia, I would like to have boundary conditions defined as Julia functions. However, I ran into the “too new for this world problem”. It took me quite a while to com…

---

## [How to deal with structure elements?](https://discourse.julialang.org/t/how-to-deal-with-structure-elements/70814)

<div class="topic-metadata">

**Author:** [@Amro](https://discourse.julialang.org/u/Amro)\
**Replies:** 6\
**Last updated:** [November 2, 2021, 5:47pm UTC](https://discourse.julialang.org/t/how-to-deal-with-structure-elements/70814 "2021-11-02T17:47:41Z")

</div>

I have the below MWE, in which at some points I need to check the field id of all elements of structure S (i.e., CP) before I continue add elements to CP, but I am having the below error. Any idea to solve it? In other w…

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

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