# Questions tagged [julia]

3530 questions

1

255

Views

### division operator with array broadcasting in Julia

I am able to multiple a constant into an array but was unable to do the same for the division operator. Expected? julia> 2 * [1,2,3] 3-element Array{Int64,1}: 2 4 6 julia> 2 / [1,2,3] ERROR: MethodError: no method matching /(::Int64, ::Array{Int64,1}) Closest candidates are: /(::Union{Int128, Int16...
fatdragon

1

87

Views

### In Julia: initialize fields with nothing

I have a mutable struct with optional fields like this: mutable struct MyStruct field1::Union{Int, Nothing} field2::Union{String, Nothing} field3::Union{Int, Nothing} field4::Union{String, Nothing} # ... end I can now write a default constructor which initializes the fields with nothing: MyStruct()...
Michael

1

62

Views

### Editing a value inside a for loop

In Julia, I'm very surprised the following does not work: # Make a random value val = rand() # Edit it *inside an if statement in a for loop* for i in 1:10 println('current value of val = ', val) if true val = val * 2. end end Trying to run this leads to: UndefVarError: val not defined The issue a...
Cliff AB

1

39

Views

### Does @everywhere not load a function on the master?

I made a module with an if condition on the number of cores. If the number of cores is more than 1 the route is parallel; otherwise, it goes the serial route as seen in the code below module mymodule import Pkg using Distributed if nworkers() > 1 @everywhere using Pkg @everywhere Pkg.activate('.') @...

3

74

Views

### using Julia 1.0 findmax equivalent of numpy.argmax

In Julia I want to find the column index of a matrix for the maximum value in each row, with the result being a Vector{Int}. Here is how I am doing it currently (Samples has 7 columns and 10,000 rows): mxindices = [ i[2] for i in findmax(Samples, dims = 2)[2]][:,1] This works but feels rather clumsy...
John Zicker

1

86

Views

### Julia - Printing or Writing in a file a Backslash in a String

I need, in Julia to write in a file, a LaTeX command, here is a minimal example : open('./file.tex', 'w') do f foo::Int = 5 # write(f, '$foo\hline \n') - This is what I would like to do # write(f, '$foo \\ \n') - This is another thing I want to do, and it works # write(f, '\$foo \\\h...
J.Khamphousone

1

103

Views

### Julia - describe() function display incomplete summary statistics

I'm trying basic data analysis with Julia I'm following this tutorial with the train datasets that can be found here (the one named train_u6lujuX_CVtuZ9i.csv) with the following code: using DataFrames, RDatasets, CSV, StatsBase train = CSV.read('/Path/to/train_u6lujuX_CVtuZ9i.csv'); describe(train[...
ecjb

1

129

Views

### Julia : How to convert vector of type string to type numeric (Float64)

In Julia 1.1 I want to convert a vector of type string to type numeric (Float64) here is the vector: string = ['2.2', '3,3', '4.4']; I tried the following line without success: x = convert(Float64, string) x = convert(DataVector{Float64}, string) x = map(x->parse(Float64,x),string) x = parse(Float...
ecjb

2

70

Views

### Why is a Julia function name (without arguments) silently ignored?

I have a script that defines a function, and later intended to call the function but forgot to add the parentheses, like this: function myfunc() println('inside myfunc') end myfunc # This line is silently ignored. The function isn't invoked and there's no error message. After a while I did figure o...
tompark

2

41

Views

### Choosing a set of values in an array

The following code a=1:1:10 collect(a) a[a.>4] returns the expected 6-element Array{Int64,1}: 5 6 7 8 9 10 Whereas, a[(a.>4) & (a.
Schlator Borgenson

1

41

Views

### Make a row or column of a matrix all zero's [Julia]

I want to make all values in a row or column of a Matrix zero's (Float64 in this case) without resorting to a manual for loop. fill! and zero work on the entire matrix, but not on an individual column or row (at least my attempts have failed... ie., fill!(tester[:,1],0.0) doesn't work. Here is an ex...
Charlie Crown

1

100

Views

### Creating Arrays from Ranges in Julia without using Collect()

I am a bit puzzled by this behavior in Julia when creating arrays from ranges. I want to know the underlying mechanics of the following. A = [1:10] Results in 1-element Array{UnitRange{Int64},1} which is not what I wanted. Above code creates an Array of UnitRange. Julia documentation recommends usin...
spectramax

1

59

Views

### Implementing Multivariate Newton's Method in Julia

I am attempting to implement the multivariate Newton's method in Julia, but have run into a 'no metehod matching' error. Below is my implementation and the code I use to call it. function newton(f::Vector, J::Matrix, x::Vector) h = Inf64 tolerance = 10^(-10) while (norm(h) > tolerance) h = J(x)\f(x)...
K. Claesson

1

41

Views

### How to inherit from a regular matrix

using ShiftedArrays struct CircularMatrix{T}
BAR

0

51

Views

### Julia traversing the expression tree containing broadcast results in unintended tuples

I am trying to understand Metaprogramming in Julia. I wrote the following code function traversal!(x::Expr,mem) for xx in x.args if isa(xx,Expr) push!(mem,xx) traversal!(xx,mem) end end end expr=:(sum((x-cos(W2*sin(W1*x+b1)+b2))^2)) mem=[] a=traversal!(expr,mem) I expect mem to be :((x - cos(W2 *...
user2741736

0

165

Views

### What's wrong with my Euclidean Distance Calculation? (Julia)

I'm trying to compute the Perceptually Important Points by using three different methods. Euclidean Distance; Perpendicular Distance; Vertical Distance. Method 2 and 3 gives me the same Point, but Euclidean distance not. Can't find the mistake I made. Hope someone can help me. pt = 7.6 #pt _t = 1...
jupiter

0

98

Views

### How to run an mpi executable from julia

I want to call an MPI exectable from Julia in a Jupyter notebook. Doing cmd = Cmd(mpiexec -np 4 name_of_executable) run(cmd) creates 4 processes, but they all use 25% cpu on one core. Is there a way to have it run 100% on four separate cores?
Jeroen

0

90

Views

### Automatic Differentiation in Julia: Hessian from ReverseDiffSparse

How can I evaluate the Hessian of a function in Julia using automatic differentiation (preferably using ReverseDiffSparse)? In the following example, I can compute and evaluate the gradient at a point values through JuMP: m = Model() @variable(m, x) @variable(m, y) @NLobjective(m, Min, sin(x) + sin(...
jjjjjj

0

71

Views

### Julia JuMP garbage collection time

I'm new to Julia and is trying to use JuMP to solve a NLP, below is the code m = JuMP.Model(solver=Ipopt.IpoptSolver(max_iter=50,tol=1e-6)) function lkhf(x1,x2,x3,x4,x5,x6,x7,x8) x = [x1,x2,x3,x4,x5,x6,x7,x8] @time ll = loglikelihood(x,pdpoeFacSim,intercept, pdpoeFacMean, pdpoeFacInitial, pdpoeTarge...
lsppppp

1

280

Views

### Problems with replacing missing values in a DataFrame with Julia 0.6.2

So, I will preface this by saying that I am new I the Julia language and trying to work through some tutorials on handling data sets. But I seem to be hitting a problem with handling missing values and cannot seem to figure out what is wrong. Specifically: I have a 11 x 5 DataFrame containing some t...
Charles Munson

1

44

Views

### Run function in same module and file in different process

If I have the following Julia code snippet, is there any way I can run the for loop with multiple processes without putting complicated into an extra file and doing something like @everywhere include('complicated.jl')? Otherwise, the processes don't seem to be able to find the function. function com...
elya5

0

204

Views

### PyPlot savefig() error 'TrueType font is missing table' when using ttc font

I am using PyPlot package from Julia language on macOS 10.13. Here is my code that generates the problem: using PyPlot PyPlot.svg(true) function myplot() my_font=matplotlib[:font_manager][:FontProperties](fname = '/System/Library/Fonts/Helvetica.ttc') fig, ax = subplots() ax[:plot](rand(10), rand(10...
Norman

0

36

Views

### Measuring memory usage of distributed arrays

I've been having trouble measuring the memory usage of distributed arrays and could not find a solution on Julia Discourse. Consider the following example. addprocs(2) @everywhere using DistributedArrays m = [rand(100,100) for i in 1:1000] d = distribute(m) How much memory does the array d use? I...
Christopher Fisher

1

44

Views

### Can I use a _FillValue when reading a netCDF file in Julia?

I use the package NetCDF.jl. I have a netCDF file file.nc which contains variable var1. In principle, var1 contains possitive values. A mask value of var1 is defined in the netCDF file, namely _FillValue = -1.e+34. However, if I ncread('file.nc', 'var1'), var1 presents the _FillValue as -1.e+34,...
Marco van Hulten

1

86

Views

### Developing reader for onnx models

I am trying to make a reader for onnx models in Julia. Generally, onnx models consist of a model.pb file, which contains metadata about the model. However, I am not able to figure out how can I use protocol buffers or Julia implementation of protocol buffers (ProtoBuf.jl) to generate data structure...
Ayush

0

41

Views

### builing Pardiso 5 on Mac with Julia

I'm trying to build Pardiso 5 on Mac 10.12.6 through Julia but am having issues. I added the Pardiso package through Julia, then I followed the Pardiso manual (p.33/69) and set LD_LIBRARY_PATH=~/.julia/v0.6/Pardiso/deps/libpardiso500-MACOS-X86-64.dylib from my .bash_profile. Then I run Pkg.build('P...
jjjjjj

2

202

Views

### Julia function timeout using async and remotecall_fetch fails to find function

I'm trying to kill execution of a function when it times out. Tried to leverage the post here: Julia: Can you set a time limit on eval It errored on RemoteRef is undefined (I'm using v0.6.0). Replaced RemoteRef with Channel(1). Now the error is MethodError: no method matching remotecall_fetch (::I...
Tims

0

88

Views

### Julia using Slurm invokes only one node

srun --nodes=3 hostname returns successfully all the 3 node names but srun --nodes=3 julia test.jl fails with error below where test.jl is given at the end here Worker 2 terminated. ERROR (unhandled task failure): Version read failed. Connection closed by peer. Stacktrace: [1] process_hdr(::TCPSocke...
Tims

2

95

Views

### Unexpected behavior in Julia boolean comparison

I'm testing different parametrization of the CDF of the logistic function and comparing the results and the effect on the curve of the different parameters. using Distributions # Vector of x to test the different functions x = collect(0:20) Logis = Logistic(10, 1) # PDF of Logistic function in Jul...
Alejo

1

470

Views

### IJulia for Julia v0.7

I tried building the latest (dev) version of Julia (v0.7) and want to use this kernel from Jupyter Notebook. When I tried running Pkg.add('IJulia') and building the module, the build failed. The errors I get are along the lines of Error: ------------------------------------------------------------...
jjjjjj

0

417

Views

### Unable to start Julia in Atom

I get these error messages everytime I try to run a Julia command. I am starting Atom from the command line. I am not sure what else I am doing incorrectly in the setup. juno-msg-precompilingINFO: Precompiling module Atom. ERROR: LoadError: could not open file /Users/John/.julia/v0.6/MbedTLS/sr...
qq3254

0

71

Views

### label boxplot extreme points in julia using Plotly Backend

i'm plotting a boxplot using plotlyJS backend for Plots in Julia 0.6.2 And i'm trying to make it possible to show particular labels (strings) for the points that are extreme. (so we can identify them easily). check the image for further details enter image description here code: using Plots plotlyjs...
inarighas

1

106

Views

### How to implement custom serialization/deserialization for a struct in Julia?

The default implementation of Base.serialize and Base.deserialize do the serialization/deserialization for the whole given object. What is the correct way of excluding a field from being serialized and still be able to deserialize it correctly? Here is a simplified code sample: # The target struct s...

0

31

Views

### List of keyword arguments in plot recipe definition

I have originally opened an issue in RecipesBase.jl, but I think this is just me not understanding the machinery of plot recipes. Why the code below fails when I try to pass in a list of keywords with the ... syntax? using RecipesBase @userplot FooPlot @recipe function f(fp::FooPlot; a=1, b=2, kwarg...
juliohm

0

126

Views

### Removing background on a 3d plot Julia

I am having some real trouble trying to plot nice things with Julia. I first used PyPlot which I was happy with but I had to be able to change the angle on a 3D plots (in that case using surface) so I now use Plots directly with the camera speficication. I would like to remove the background on a 3...
ChrlTsr

0

152

Views

### Julia calling Fortran. signal (11): Segmentation fault error

I am using a very large code in Fortran. It is called sapick6.f90. If I compile this code: gfortran -O3 -o sapick6 sapick6.f90 and run it: ./sapick6 I have always the same exact result (as expected). It has random number subroutines, but the seed, at the beginning is always the same, as it reads inp...
german brunini

2

158

Views

### Fuzzy C-means clustering in ImageSegmentation.jl

I am trying to cluster different regions of an image using Fuzzy C-means clustering with ImageSegmentation.jl using ImageSegmentation, Images fl = load('flower.jpg') fuzzy_fl = fuzzy_cmeans(fl,3,2) It gives an error like this: MethodError: no method matching fuzzy_cmeans(::Base.ReshapedArray{Float64...
Akshay Sharma

0

38

Views

### Enable tab completion to find file in Julia outside working directory

How can I enable tab completion in Julia with a function I wrote that loads a file outside of the working directory? Tab completion is super nice, but it only seems to work for files in my working directory. e.g. I store all of my files in a directory foo and I wrote a function to conveniently read...
Cokes

0

128

Views

### How to get intermediate Integer solutions when solving a MIP in Julia (JuMP)?

I am solving a MIP model using CPLEX in Julia. I know CPLEX has a so-called Solution Pool where all the intermediate integer solutions during the solving process are stored. Is there a way of accessing those solutions using Julia (JuMP)?
Berni

1

64

Views

### non-boolean (UInt16) used in boolean context

I'm getting an error: TypeError: non-boolean (UInt16) used in boolean context After some debugging the error is coming from this while loop. current_value = UInt16(6) bit = UInt16(8) while (current_value & bit) bit >>= 1 end What's wrong?
Jimbo