julia

In Julia, is there a way to pass a variable from a local scope to the enclosing local scope?

我的梦境 提交于 2021-02-07 19:42:24
问题 I am writing some Julia code, wrapped in a function for performance. I need to pass a variable created in a loop to an outer loop but would like to avoid globals for performance reasons: function f() for i=1:1 for j=1:1 a=2 end println(a) end end f() This throws an error since the scope of the i-loop does not know about the variable a . Definining a first within the scope in question works: function f() for i=1:1 a=0 for j=1:1 a=2 end println(a) end end f() I am not super happy with that

Julia - how to subscribe via WebSockets

旧巷老猫 提交于 2021-02-07 08:16:24
问题 I would like to subscribe to some data feed using Websockets using Julia. For example, from the linux terminal, I can successfully get data like this: wscat -c wss://www.bitmex.com/realtime {"op": "subscribe", "args": ["orderBookL2_25:XBTUSD"]} Now in Julia, I cannot find a solution. I have tried the following, but it crashes Julia: using WebSockets, JSON uri = "wss://www.bitmex.com/realtime" json_part = "{'op': 'subscribe', 'args': ['orderBookL2_25:XBTUSD']}" inbox = Channel{String}(10)

Julia - how to subscribe via WebSockets

。_饼干妹妹 提交于 2021-02-07 08:15:32
问题 I would like to subscribe to some data feed using Websockets using Julia. For example, from the linux terminal, I can successfully get data like this: wscat -c wss://www.bitmex.com/realtime {"op": "subscribe", "args": ["orderBookL2_25:XBTUSD"]} Now in Julia, I cannot find a solution. I have tried the following, but it crashes Julia: using WebSockets, JSON uri = "wss://www.bitmex.com/realtime" json_part = "{'op': 'subscribe', 'args': ['orderBookL2_25:XBTUSD']}" inbox = Channel{String}(10)

Julia | DataFrame | Replacing missing Values

余生颓废 提交于 2021-02-07 05:44:44
问题 How can we replace missing values with 0.0 for a column in a DataFrame ? 回答1: There are a few different approaches to this problem (valid for Julia 1.x): Base.replace! Probably the easiest approach is to use replace! or replace from base Julia. Here is an example with replace! : julia> using DataFrames julia> df = DataFrame(x = [1, missing, 3]) 3×1 DataFrame │ Row │ x │ │ │ Int64⍰ │ ├─────┼─────────┤ │ 1 │ 1 │ │ 2 │ missing │ │ 3 │ 3 │ julia> replace!(df.x, missing => 0); julia> df 3×1

Julia syntax highlighting in julia-vim

北慕城南 提交于 2021-02-07 05:15:59
问题 I use gvim with julia-vim for editing julia code. I am using julia 0.5 on a mac and installed julia-vim with vundle. My problem is that files with the .jl extension do not have appropriate highlighting. For example, if is highlighted but for is not. Any solution for this? 回答1: .jl files are sometimes recognized as lisp files by default, (blame Sawfish) so that's probably the syntax highlighting you're getting. (type defun and progn and etc and see if the pretty colors pop up) You were close

Julia syntax highlighting in julia-vim

若如初见. 提交于 2021-02-07 05:14:52
问题 I use gvim with julia-vim for editing julia code. I am using julia 0.5 on a mac and installed julia-vim with vundle. My problem is that files with the .jl extension do not have appropriate highlighting. For example, if is highlighted but for is not. Any solution for this? 回答1: .jl files are sometimes recognized as lisp files by default, (blame Sawfish) so that's probably the syntax highlighting you're getting. (type defun and progn and etc and see if the pretty colors pop up) You were close

I have a high-performant function written in Julia, how can I use it from Python?

让人想犯罪 __ 提交于 2021-02-07 04:45:10
问题 I have a found a Julia function that nicely does the job I need. How can I quickly integrate it to be able to call it from Python? Suppose the function is f(x,y) = 2x.+y What is the best and most elegent way to use it from Python? 回答1: Assuming your Python and Julia are installed you need to take the following steps. Run Julia and install PyCall using Pkg pkg"add PyCall" Put your code into a Julia package using Pkg Pkg.generate("MyPackage") In the folder src you will find MyPackage.jl , edit

Parallel computing in Julia - running a simple for-loop on multiple cores

扶醉桌前 提交于 2021-02-06 10:20:49
问题 For starters, I have to say I'm completely new to parallel computing (and know close to nothing about computer science), so my understanding of what things like "workers" or "processes" actually are is very limited. I do however have a question about running a simple for-loop that presumably has no dependencies between the iterations in parallel. Let's say I wanted to do the following: for N in 1:5:20 println("The N of this iteration in $N") end If I simply wanted these messages to appear on

Parallel computing in Julia - running a simple for-loop on multiple cores

三世轮回 提交于 2021-02-06 10:19:25
问题 For starters, I have to say I'm completely new to parallel computing (and know close to nothing about computer science), so my understanding of what things like "workers" or "processes" actually are is very limited. I do however have a question about running a simple for-loop that presumably has no dependencies between the iterations in parallel. Let's say I wanted to do the following: for N in 1:5:20 println("The N of this iteration in $N") end If I simply wanted these messages to appear on

How to repeat elements in list n times?

微笑、不失礼 提交于 2021-02-05 06:29:06
问题 How do I repeat each element of a list n times and form a new list? For example: x=[1,2,3,4] n=3 Looking for: [1,1,1,2,2,2,3,3,3,4,4,4] 回答1: An inner argument to repeat is what I was looking for: repeat([1, 2, 3, 4], inner = 3) 回答2: Also list comprehension: x = [1,2,3,4] n = 3 result = [i for i in x for j in 1:n] 来源: https://stackoverflow.com/questions/60234868/how-to-repeat-elements-in-list-n-times