julia

Julia DataFrames - How to do one-hot encoding?

我怕爱的太早我们不能终老 提交于 2021-02-04 22:34:14
问题 I'm using Julia's DataFrames.jl package. In it, I have a dataframe with a columns containing a list of strings (e.g. ["Type A", "Type B", "Type D"]). How does one then performs a one-hot encoding? I wasn't able to find a pre-built function in the DataFrames.jl package. Here is an example of what I want to do: Original Dataframe col1 | col2 | 102 |[a] | 103 |[a,b] | 102 |[c,b] | After One-hot encoding col1 | a | b | c | 102 | 1 | 0 | 0 | 103 | 1 | 1 | 0 | 102 | 0 | 1 | 1 | 回答1: It is easy

How to access an API via Julia HTTP

橙三吉。 提交于 2021-02-04 19:31:06
问题 Access the Betfair Exchange API using Julia I've been using Julia for about 2mths now, and have recently been trying to use Julia to access the Betfair API. Note about this service are here. https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Getting+Started Whilst I can get the Python example working (& I have an appKey & sessionToken though not shown), I've not been able to successfully translate this Python into Julia. In example below I get a StatusError 400 response

Julia vs. MATLAB - Distance Matrix - Run Time Test

主宰稳场 提交于 2021-02-04 18:51:05
问题 I started learning Julia not a long time ago and I decided to do a simple comparison between Julia and Matlab on a simple code for computing Euclidean distance matrices from a set of high dimensional points. The task is simple and can be divided into two cases: Case 1: Given two datasets in the form of n x d matrices, say X1 and X2, compute the pair wise Euclidean distance between each point in X1 and all the points in X2. If X1 is of size n1 x d, and X2 is of size n2 x d, then the resulting

Julia: Broadcasting Functions with Keyword Arguments

梦想与她 提交于 2021-02-04 17:31:06
问题 Suppose we have a composite type: mutable struct MyType{TF<:AbstractFloat, TI<:Integer} a::TF b::TF end We define a constructor function MyType(a; b = 1.0) return MyType(a, b) end I can broadcast MyType over an array of a 's, but how can I do that for b 's? I tried to do MyType.([1.0, 2.0, 3.0]; [:b, 1.0, :b, 2.0, :b, 3.0,]) But, this does not work. Note that the above example is totally artificial. In reality, I have a composite type that takes in many fields, many of which are constructed

How to pin a package to a certain version using Julia 0.7?

醉酒当歌 提交于 2021-01-29 08:22:43
问题 I'm using Atom Julia 0.7 on Ubuntu. I'd like to pin the package GDAL to version 0.1.2. I found this link, Julia: how I "fix" a package at a particular version? but need more detailed information. Julia> Pkg.pin(PackageSpec(name = “GDAL”, version = “0.1.2”)) Error: the following package names could not be resolved: * GDAL(add… in manifest but not in project) Please specify by known ‘name=uuid’. 回答1: Before you can pin a package to a specific version, it needs to be added. As docstring

Remove null column on julia array

岁酱吖の 提交于 2021-01-28 14:36:23
问题 Beggining with Julia, I'm looking to remove the columns with 0 values. I have an array as bellow with a lot of null columns which I would like to remove. 115×40 Array{Float64,2}: -0.0 -0.0 -0.0 -0.0 … -0.0 0.0 -0.0 0.0 -0.0 -0.0 -0.0 0.0 0.0 0.0 -0.0 -0.0 -0.0 -0.0 -0.0 0.0 -0.0 0.0 0.0 -0.0 -0.0 -0.0 0.0 0.0 0.0 0.0 0.0 -0.0 -0.0 0.0 0.0 -0.0 1.0 -0.0 0.0 … -0.0 0.0 0.0 -0.0 -0.0 0.0 -0.0 -0.0 0.0 0.0 0.0 -0.0 -0.0 -0.0 0.0 0.0 0.0 0.0 -0.0 0.0 -0.0 -0.0 0.0 0.0 ⋮ ⋱ 0.0 1.0 -0.0 -0.0 0.0 -0

Remove null column on julia array

让人想犯罪 __ 提交于 2021-01-28 14:35:48
问题 Beggining with Julia, I'm looking to remove the columns with 0 values. I have an array as bellow with a lot of null columns which I would like to remove. 115×40 Array{Float64,2}: -0.0 -0.0 -0.0 -0.0 … -0.0 0.0 -0.0 0.0 -0.0 -0.0 -0.0 0.0 0.0 0.0 -0.0 -0.0 -0.0 -0.0 -0.0 0.0 -0.0 0.0 0.0 -0.0 -0.0 -0.0 0.0 0.0 0.0 0.0 0.0 -0.0 -0.0 0.0 0.0 -0.0 1.0 -0.0 0.0 … -0.0 0.0 0.0 -0.0 -0.0 0.0 -0.0 -0.0 0.0 0.0 0.0 -0.0 -0.0 -0.0 0.0 0.0 0.0 0.0 -0.0 0.0 -0.0 -0.0 0.0 0.0 ⋮ ⋱ 0.0 1.0 -0.0 -0.0 0.0 -0

Converting SuiteSparse.SPQR.QRSparseQ to SparseMatrixCSC?

依然范特西╮ 提交于 2021-01-28 11:17:46
问题 I have this problem that converting the native sparse format for the QR decomposition of a sparse Matrix takes forever. However, I need it in the CSC format to use it for further computations. using LinearAlgebra, SparseArrays N = 1000 A = sprand(N,N,1e-4) @time F = qr(A) @time F.Q @time Q_sparse = sparse(F.Q) 0.000420 seconds (1.15 k allocations: 241.017 KiB) 0.000008 seconds (6 allocations: 208 bytes) 6.067351 seconds (2.00 M allocations: 15.140 GiB, 36.25% gc time) Any suggestions? 回答1:

Efficient way to extract and collect a random subsample of a generator in Julia

此生再无相见时 提交于 2021-01-28 02:45:37
问题 Consider a generator in Julia that if collected will take a lot of memory g=(x^2 for x=1:9999999999999999) I want to take a random small subsample (Say 1%) of it, but I do not want to collect() the object because will take a lot of memory Until now the trick I was using was this temp=collect((( rand()>0.01 ? nothing : x ) for x in g)) random_sample= temp[temp.!=nothing] But this is not efficient for generators with a lot of elements, collecting something with so many nothing elements doesnt

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

独自空忆成欢 提交于 2021-01-28 02:32:20
问题 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