julia

How to scale the fontsizes using Plots.jl

梦想与她 提交于 2021-01-28 01:36:02
问题 is there a way to rescale all the fontsizes (legend, tickslabels, axislabels…) at once? Original question from Filippo Vicentini on Slack. 回答1: Individual font sizes can be controlled with the titlefontsize , tickfontsize , legendfontsize , tickfontsize , guidefontsize and legendtitlefontsize attributes, but I get that this can be quite tedious. There is also the thickness_scaling attribute. plot(rand(10), thickness_scaling = 0.5) However, this also affects the line widths. The third option

How to define an array of any float type in Julia?

久未见 提交于 2021-01-28 01:29:01
问题 I tried Array{AbstractFloat,1} , but this does not work as Array{Float64,1} <: Array{AbstractFloat,1} is false , even though Float64 <: AbstractFloat is true . 回答1: If you want an vector which can contain any kind of floating-point value, then the correct type is Vector{AbstractFloat} , which can be constructed like this: julia> v = AbstractFloat[] AbstractFloat[] julia> push!(v, 1.5) 1-element Vector{AbstractFloat}: 1.5 julia> push!(v, big(2.0)^1000) 2-element Vector{AbstractFloat}: 1.5 1

Julia scoping: why does this function modify a global variable?

随声附和 提交于 2021-01-27 22:51:45
问题 I'm a relative newcomer to Julia, and so far I am a fan of it. But coming from years of R programming, some scoping rules leave me perplexed. Let's take this function. This behaves exactly as I would expect. function foo1(x) y = x t = 1 while t < 1000 t += 1 y += 1 end return 42 end var = 0; foo1(var) # 42 var # 0 But when doing something similar on an array, it acts as a mutating function (modifies it argument in the global scope!) function foo2(x) y = x t = 1 while t < 1000 t += 1 y[1] += 1

How to convert type of a variable when using JuMP

北城余情 提交于 2021-01-27 21:31:42
问题 I am using Julia/JuMP to implement an algorithm. In one part, I define a model with continues variables and solve the linear model. I do some other calculations based on which I add a couple constraints to the model, and then I want to solve the same problem but with integer variables. I could not use convert() function as it does not take variables. I tried to define the variable again as integer, but the model did not seem to consider it! I provide a sample code here: m = Model() @defVar(m,

Using parameters from BASH file name as arguments for Julia script on cluster

你说的曾经没有我的故事 提交于 2021-01-27 11:51:49
问题 This is an extension of a previous question I asked: Using name of BASH script as input argument My goal is to write a BASH script which takes the arguments from the file's name and uses them as inputs for a Julia code I'm writing, and then submit the BASH script to a remote cluster. Using @AndriyMakukha's solution, I was able to write the following script through Torque: #!/bin/bash #PBS -l mem=10gb,nodes=1:ppn=2,walltime=1:00:00 #PBS -N ES_100_20_100 #PBS -j oe #PBS -o ./log/julia.${PBS

MethodError when dispatching on a parametric vector of vectors

江枫思渺然 提交于 2021-01-27 06:39:25
问题 I've written a function that dispatches on a vector of vectors of Integer s. However, I get a MethodError when I try to use it: julia> foo(x::Vector{Vector{<:Integer}}) = last(last(x)); julia> x = [[1], [2, 3], [4, 5, 6]] 3-element Array{Array{Int64,1},1}: [1] [2, 3] [4, 5, 6] julia> foo(x) ERROR: MethodError: no method matching foo(::Array{Array{Int64,1},1}) Closest candidates are: foo(::Array{Array{#s17,1} where #s17<:Integer,1}) at REPL[1]:1 Why doesn't this work? 回答1: The notation here is

MethodError when dispatching on a parametric vector of vectors

痞子三分冷 提交于 2021-01-27 06:36:12
问题 I've written a function that dispatches on a vector of vectors of Integer s. However, I get a MethodError when I try to use it: julia> foo(x::Vector{Vector{<:Integer}}) = last(last(x)); julia> x = [[1], [2, 3], [4, 5, 6]] 3-element Array{Array{Int64,1},1}: [1] [2, 3] [4, 5, 6] julia> foo(x) ERROR: MethodError: no method matching foo(::Array{Array{Int64,1},1}) Closest candidates are: foo(::Array{Array{#s17,1} where #s17<:Integer,1}) at REPL[1]:1 Why doesn't this work? 回答1: The notation here is

How to set Julia Environment for IJulia Jupyter notebook?

自作多情 提交于 2021-01-27 06:04:34
问题 I am encountering package compatibility issues within my global Julia environment for specific packages I want to use in a Jupyter notebook. Is there a way to tell IJulia to use a different environment instead of my global one? 回答1: The default IJulia kernel sets --project=@. so the most convenient way (IMO) is to just keep your project in the same folder as the notebook. The result is that the correct project is used from the start and you don't have to worry about activating it while in the

How to set Julia Environment for IJulia Jupyter notebook?

寵の児 提交于 2021-01-27 06:03:40
问题 I am encountering package compatibility issues within my global Julia environment for specific packages I want to use in a Jupyter notebook. Is there a way to tell IJulia to use a different environment instead of my global one? 回答1: The default IJulia kernel sets --project=@. so the most convenient way (IMO) is to just keep your project in the same folder as the notebook. The result is that the correct project is used from the start and you don't have to worry about activating it while in the

Read CSV files faster in Julia

那年仲夏 提交于 2021-01-27 05:40:56
问题 I have noticed that loading a CSV file using CSV.read is quite slow. For reference, I am attaching one example of time benchmark: using CSV, DataFrames file = download("https://github.com/foursquare/twofishes") @time CSV.read(file, DataFrame) Output: 9.450861 seconds (22.77 M allocations: 960.541 MiB, 5.48% gc time) 297 rows × 2 columns This is a random dataset, and a python alternate of such operation compiles in fraction of time compared to Julia. Since, julia is faster than python why is