julia

how to show all elements of vectors and matrices in Julia

十年热恋 提交于 2020-01-23 16:20:37
问题 When I have many elements in an array, Julia REPL only shows some part of it. For example: julia> x = rand(100,2); julia> x 100×2 Array{Float64,2}: 0.277023 0.0826133 0.186201 0.76946 0.534247 0.777725 0.942698 0.0239694 0.498693 0.0285596 ⋮ 0.383858 0.959607 0.987775 0.20382 0.319679 0.69348 0.491127 0.976363 Is there any way to show all elements in the vertical form as above? print(x) or showall(x) put it in an ugly form without line changes. 回答1: NOTE: in 0.7, Base.STDOUT has been renamed

Discretizing a continuous probability distribution

岁酱吖の 提交于 2020-01-23 12:20:03
问题 Recognizing that this may be as much a statistical question as a coding question, let's say I have a normal distribution created using Distributions.jl: using Distributions mydist = Normal(0, 0.2) Is there a good, straightforward way that I should go about discretizing such a distribution in order to get a PMF as opposed to a PDF? In R, I found that the actuar package contains a function to discretize a continuous distribution. I failed to find anything similar for Julia, but thought I'd

Getting 1D Subsets of Multi dimensional arrays in julia

走远了吗. 提交于 2020-01-23 11:54:32
问题 I have a multi dimensional array in julia: julia> ac.value 3x100x3 Array{Float64,3}: [:, :, 1] = 0.29238 0.0751815 0.00843636 … -0.0143826 0.0403283 0.0225896 0.263146 0.080687 0.000462262 -0.00635778 0.0307563 0.0379104 0.992458 0.986423 0.980587 0.561173 0.55516 0.549105 [:, :, 2] = 0.362155 0.13406 0.0741124 … 0.0231614 0.0156455 0.0121797 0.325581 0.11181 0.0447847 0.0098042 0.0193873 0.0146943 0.914888 0.852297 0.796608 -0.0500265 -0.0551787 -0.0520171 [:, :, 3] = 0.269976 0.108082 0

julian way to do python's yield (and yield from)

江枫思渺然 提交于 2020-01-23 10:43:46
问题 What is julian way to do yield (and yield from) as python do? Edit: I will try to add small example in python. Think 4x4 chess board. Find every N moves long path chess king could do. Don't waste memory -> make generator of every path. if we sign every position with numbers: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 point 0 has 3 neighbors (1, 4, 5). We could find table for every neighbors for every point: NEIG = [[1, 4, 5], [0, 2, 4, 5, 6], [1, 3, 5, 6, 7], [2, 6, 7], [0, 1, 5, 8, 9], [0, 1, 2,

In Julia, How can I column-normalize a sparse matrix?

怎甘沉沦 提交于 2020-01-23 08:34:26
问题 If I have constructed a sparse matrix using the sparse(i, j, k) constructor, how can I then normalize the columns of the matrix (so that each column sums to 1)? I cannot efficiently normalize the entries before I create the matrix, so any help is appreciated. Thanks! 回答1: The easiest way would be a broadcasting division by the sum of the columns: julia> A = sprand(4,5,.5) A./sum(A,1) 4x5 Array{Float64,2}: 0.0 0.0989976 0.0 0.0 0.0795486 0.420754 0.458653 0.0986313 0.0 0.0 0.0785525 0.442349 0

Julia DataFrame output functions

喜欢而已 提交于 2020-01-23 07:58:46
问题 What Julia functions can output a DataFrame so it is converted into text other than the ones shown below? using DataFrames A = DataFrame(randn(10, 7)); print("\n\n\n", "A = DataFrame(randn(10, 7))") print("\n\n\n","print(A)\n") print(A) print("\n\n\n","show(A)\n") show(A) print("\n\n\n","show(A, true)\n") show(A, true) print("\n\n\n","show(A, false)\n") show(A, false) print("\n\n\n","showall(A)\n") showall(A) print("\n\n\n","showall(A, true)\n") showall(A, true) print("\n\n\n","showall(A,

Julia DataFrame output functions

旧巷老猫 提交于 2020-01-23 07:56:48
问题 What Julia functions can output a DataFrame so it is converted into text other than the ones shown below? using DataFrames A = DataFrame(randn(10, 7)); print("\n\n\n", "A = DataFrame(randn(10, 7))") print("\n\n\n","print(A)\n") print(A) print("\n\n\n","show(A)\n") show(A) print("\n\n\n","show(A, true)\n") show(A, true) print("\n\n\n","show(A, false)\n") show(A, false) print("\n\n\n","showall(A)\n") showall(A) print("\n\n\n","showall(A, true)\n") showall(A, true) print("\n\n\n","showall(A,

Customized display of composite types in Julia

隐身守侯 提交于 2020-01-22 12:16:31
问题 Suppose you define a new composite type in Julia and a variable of that type: type MyType α::Int64 β::Vector{Float64} γ::Float64 MyType(α::Int64, β::Vector{Float64}, γ::Float64) = new(α, β, γ) end mt = MyType(5, [1.2, 4.1, 2], 0.2) Now if you are in REPL mode, you can simply check the value of mt by typing mt and pressing Enter: mt MyType(5,[1.2,4.1,2.0],0.2) If I want to customize the way variables of MyType are displayed, I can define a function and use it like customized_display(mt) :

How to define global variables to be shared later in Julia

非 Y 不嫁゛ 提交于 2020-01-22 02:30:07
问题 I have a module in file global.jl which defines a global multidimensional array named "data": module Global export data # GLOBAL DATA ARRAY data = zeros(Int32, 20, 12, 31, 24, 60, 5); end I have a main.jl which uses this global variable: include("global.jl") using .Global println(data[14,1,15,18,0,1]) And I get the following error: $ time /usr/local/julia-1.2.0/bin/julia main.jl ERROR: LoadError: BoundsError: attempt to access 20Ã12Ã31Ã24Ã60Ã5 Array{Int32,6} at index [14, 1, 15, 18, 0, 1]

How to define global variables to be shared later in Julia

不想你离开。 提交于 2020-01-22 02:30:06
问题 I have a module in file global.jl which defines a global multidimensional array named "data": module Global export data # GLOBAL DATA ARRAY data = zeros(Int32, 20, 12, 31, 24, 60, 5); end I have a main.jl which uses this global variable: include("global.jl") using .Global println(data[14,1,15,18,0,1]) And I get the following error: $ time /usr/local/julia-1.2.0/bin/julia main.jl ERROR: LoadError: BoundsError: attempt to access 20Ã12Ã31Ã24Ã60Ã5 Array{Int32,6} at index [14, 1, 15, 18, 0, 1]