julia

In my Julia 1.0.0 REPL, LOAD_PATH returns unexpected results

谁说我不能喝 提交于 2020-01-14 18:59:47
问题 My Julia REPL Help provides the following for LOAD_PATH: help?> LOAD_PATH search: LOAD_PATH LOAD_PATH An array of paths for using and import statements to consdier as project environments or package directories when loading code. See Code Loading. Here is my output for LOAD_PATH at the prompt: julia> LOAD_PATH # What is the output below? 3-element Array{String,1}: "@" "@v#.#" "@stdlib" The output shown above for LOAD_PATH seems strange. Any suggestions? 回答1: What you see there is the DEFAULT

In my Julia 1.0.0 REPL, LOAD_PATH returns unexpected results

拟墨画扇 提交于 2020-01-14 18:59:15
问题 My Julia REPL Help provides the following for LOAD_PATH: help?> LOAD_PATH search: LOAD_PATH LOAD_PATH An array of paths for using and import statements to consdier as project environments or package directories when loading code. See Code Loading. Here is my output for LOAD_PATH at the prompt: julia> LOAD_PATH # What is the output below? 3-element Array{String,1}: "@" "@v#.#" "@stdlib" The output shown above for LOAD_PATH seems strange. Any suggestions? 回答1: What you see there is the DEFAULT

Convert binary to decimal in Julia

我怕爱的太早我们不能终老 提交于 2020-01-14 10:42:33
问题 I'd like to convert binary to decimal in Julia. It looks like parseint() became deprecated. Is the below method the best way to do this? julia> parse(Int,"111",2) 7 回答1: Are you starting with a string? Then yes, that's the way. If you're just wanting to write a constant in binary, then it's much easier to just use the 0b111 syntax. By default, it constructs an unsigned integer (which is displayed in hexadecimal), but you can easily convert it to a signed integer with Int(0b111) . julia>

What is the difference between `UnitRange` and `Array`?

天涯浪子 提交于 2020-01-14 09:34:07
问题 I have two versions of code that seem to do the same thing: sum = 0 for x in 1:100 sum += x end sum = 0 for x in collect(1:100) sum += x end Is there a practical difference between the two approaches? 回答1: In Julia, 1:100 returns a particular struct called UnitRange that looks like this: julia> dump(1:100) UnitRange{Int64} start: Int64 1 stop: Int64 100 This is a very compact struct to represent ranges with step 1 and arbitrary (finite) size. UnitRange is subtype of AbstractRange , a type to

Why does the + function appear to work on tuples?

孤人 提交于 2020-01-14 08:30:15
问题 Using the + function on a tuple of two Int64s returns the sum: julia> +((1, 2)) 3 However, using the + function on a variable that references a tuple gives the following error: julia> a = (1, 2) (1,2) julia> +(a) ERROR: MethodError: no method matching +(::Tuple{Int64, Int64}) I'm having trouble understanding why it behaves like this, especially when the following code returns true. julia> typeof(a) == typeof((1, 2)) 回答1: Note that, contrary to what you might think, julia> :(+((1, 2))) :(1 + 2

Dummy Variables in Julia

五迷三道 提交于 2020-01-14 07:58:13
问题 In R there is nice functionality for running a regression with dummy variables for each level of a categorical variable. e.g. Automatically expanding an R factor into a collection of 1/0 indicator variables for every factor level Is there an equivalent way to do this in Julia. x = randn(1000) group = repmat(1:25 , 40) groupMeans = randn(25) y = 3*x + groupMeans[group] data = DataFrame(x=x, y=y, g=group) for i in levels(group) data[parse("I$i")] = data[:g] .== i end lm(y~x+I1+I2+I3+I4+I5+I6+I7

Fitting two curves with linear/non-linear regression

孤街醉人 提交于 2020-01-14 07:51:09
问题 I need to fit two curves(which both should belong to cubic functions) into a set of points with JuMP. I've done fitting one curve, but I'm struggling at fitting 2 curves into same dataset. I thought that if I can distribute points to curves - so if each point can only be used once - I can do it like below, but it didn't work. (I know that I can use much more complicated things, I want to keep it simple.) This is a part of my current code: # cubicFunc is a two dimensional array which accepts

Packing int and float to byte arrays in Julia

为君一笑 提交于 2020-01-14 02:10:27
问题 I am trying to find out how I can pack an integer or float value in to a byte array in Julia. In Python I would just do the following: struct.pack("<q",1) Which would give me '\x01\x00\x00\x00\x00\x00\x00\x00' or for a float: struct.pack("<f",0.1) Is there any package in Julia that provides this? Thanks! 回答1: See the StrPack package: https://strpackjl.readthedocs.org/en/latest/ This is actually one of the oldest Julia packages around. 回答2: A couple other options to StrPack.jl: julia> function

Packing int and float to byte arrays in Julia

巧了我就是萌 提交于 2020-01-14 02:10:00
问题 I am trying to find out how I can pack an integer or float value in to a byte array in Julia. In Python I would just do the following: struct.pack("<q",1) Which would give me '\x01\x00\x00\x00\x00\x00\x00\x00' or for a float: struct.pack("<f",0.1) Is there any package in Julia that provides this? Thanks! 回答1: See the StrPack package: https://strpackjl.readthedocs.org/en/latest/ This is actually one of the oldest Julia packages around. 回答2: A couple other options to StrPack.jl: julia> function

How to pass an object by reference and value in Julia?

℡╲_俬逩灬. 提交于 2020-01-13 18:53:24
问题 I know that from here: Julia function arguments follow a convention sometimes called "pass-by-sharing", which means that values are not copied when they are passed to functions. Function arguments themselves act as new variable bindings (new locations that can refer to values), but the values they refer to are identical to the passed values. Modifications to mutable values (such as Arrays) made within a function will be visible to the caller. This is the same behavior found in Scheme, most