julia

Julia: Check if elements from one vector are within another vector [duplicate]

微笑、不失礼 提交于 2020-02-25 04:41:12
问题 This question already has answers here : Vectorized “in” function in julia? (4 answers) Closed 2 years ago . I would like to check if the elements in one vector are contained within another vector. In R there is the operator %in% . For example the operator would do the following: [1,3,5,7,9,4] %in% [1,2,4,5,8,9,10,11] # [true,false,true,false,true,true] I can easily write my own only I am trying not to reinvent the wheel. 回答1: There are a number of built-ins that do something similar. indexin

Julia - dataframe - How to use string for custom output column naming in by()

倖福魔咒の 提交于 2020-02-25 02:11:10
问题 I am getting familiar with Julia Dataframes module. One thing that I haven't found a way yet to do is how to assign programmatically a custom column name of the result of a by() operation. So for example I have no problem doing the following : df = DataFrame(grp = rand(["a","b"], 100), x= rand(100), y = rand(100), z=rand(100)) by(df, :grp,result=(:x, :z)=>((x, y),) -> cov(x, y)) Giving the following dataframe 2×2 DataFrame │ Row │ grp │ result │ │ │ String │ Float64 │ ├─────┼────────┼────────

Iterating over different functions with different number of parameters in Julia

主宰稳场 提交于 2020-02-24 14:43:02
问题 I'm trying to run a loop over different functions with different number of arguments. The variables are created at runtime inside the loop, and I want to use eval at each iteration to instantiate a Struct using the variable :symbol. However, I can't do this since eval only works in the global scope. This is the MWE for the case that works: function f1(x); return x; end function f2(x1,x2); return x1+x2; end handles = [f1,f2] args =[:(x1),:(x1,x2)] x1 = 1; x2 = 1; for (i,f) in enumerate(handles

Iterating over different functions with different number of parameters in Julia

半腔热情 提交于 2020-02-24 14:42:31
问题 I'm trying to run a loop over different functions with different number of arguments. The variables are created at runtime inside the loop, and I want to use eval at each iteration to instantiate a Struct using the variable :symbol. However, I can't do this since eval only works in the global scope. This is the MWE for the case that works: function f1(x); return x; end function f2(x1,x2); return x1+x2; end handles = [f1,f2] args =[:(x1),:(x1,x2)] x1 = 1; x2 = 1; for (i,f) in enumerate(handles

Julia: Unable to load WebIO. Please make sure WebIO works for your Jupyter client.

谁说胖子不能爱 提交于 2020-02-22 04:56:36
在运行Julia时出现了这种情况:“Unable to load WebIO. Please make sure WebIO works for your Jupyter client. For troubleshooting, please see the WebIO/IJulia documentation.” 如果你没有安装Jupyter Notebook的扩展,这是由于notebook没有安装扩展导致的。注意这里的Notebook是经典的notebook。。 解决方案: 使用命令 jupyter nbextension list (这里是在cmd中,前提是已经配好Jupyter的环境变量)查看jupyter已有的扩展 打开Julia。输入以下命令安装扩展: using WebIO WebIO . install_jupyter_nbextension ( ) 安装完成后,查看Jupyter已有的扩展,在cmd中输入 jupyter nbextension list 。可以发现已经安装成功。 重启Jupyter,就可以进行使用了。。。 来源: CSDN 作者: Thingcor 链接: https://blog.csdn.net/qq_41634283/article/details/104426713

详解 CUDA By Example 中的 Julia Set 绘制GPU优化

℡╲_俬逩灬. 提交于 2020-02-06 01:21:50
笔者测试环境VS2019。 基本介绍 原书作者引入Julia Sets意在使用GPU加速图形的绘制。Julia Set 是指满足下式迭代收敛的复数集合 \[ Z_{n+1}=Z_{n}^2+C \] 环境配置 跑这个例子的主要困难应该在于配置环境。这个程序依赖于openGL中的glut库。由于VS2019的整个软件架构发生了很大变化,一些链接库和头文件的位置都发生了改变,因此一些文章中的配置方法失效了。 首先我们需要获取glut库的头文件以及动态链接库。 点击这里 cg-toolkit 获取。安装成功之后,找到C:\Program Files (x86)\NVIDIA Corporation\Cg。注意勾选安装选项的x64相关应用。 将其中的 lib 文件夹中的_glut32.lib_复制到C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\ucrt\x86 将其中的 lib.x64 文件夹中的 glut32.lib 复制到C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\ucrt\x64并且重命名其为 glut64.lib 笔者运行的是64位系统,就将 bin.x64 中的_glut32.dll_复制到C:\Windows\System32下 在这里

How to multiply multi-dimensional arrays/matrices in Julia

半腔热情 提交于 2020-02-05 13:12:27
问题 Multiplying two multi-dimensional arrays, say, a 1-dimensional with a 3-dimensional array: [1 2] * reshape(1:8,2,2,2) gives me the error message: LoadError: MethodError: `*` has no method matching *(::Array{Int64,2}, ::Array{Int64,3}) Closest candidates are: *(::Any, ::Any, !Matched::Any, !Matched::Any...) *{TA,TB}(::Union{DenseArray{TA,1},DenseArray{TA,2},SubArray{TA,1,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Int64,Range{Int64}}}},LD},SubArray{TA,2,A<:DenseArray{T,N},I<:Tuple{Vararg

Julia ---- 普通文本文件读取

雨燕双飞 提交于 2020-02-03 01:57:37
1、功能概述 #读取CSV 或者Excel 文件 ,Julia 都有成熟的工具包,如CSV.jl 读取csv文件并转为DataFrame #但是类似txt等简单的文本文件读取,是需要自己处理的。下面提供了几种读取方法 #要使用到函数有 #readline() 其中readline()读取一行数据 #readlines() 一次将所有行读取到内存 #eachline(),eachline可以获取一个迭代器 #open() close() ,可以读取并关闭文件 #write()可以写入文件,但是会覆盖文件的内容,暂时没有找到追加的操作 2、代码样例 # 默认情况下,这将丢弃换行符, words = readlines("D:/Julia/测试数据.txt") words = readline("D:/Julia/测试数据.txt") # 但如果要保留它们,可以传递关键字参数 keep=true: words = readlines("D:/Julia/测试数据.txt", keep=true) #如果已经打开了一个文件,也可以传递给readlines函数,下面的代码块会丢弃首行文本 open("D:/Julia/测试数据.txt") do io readline(io) #丢弃首行 readlines(io) end #如果不想一次加载所有文件内容

Why does this assignment inside a loop fail in Julia 0.7 and 1.0?

两盒软妹~` 提交于 2020-02-02 10:21:46
问题 (k, a, b, a1, b1) = (BigInt(2), BigInt(4), BigInt(1), BigInt(12), BigInt(4)) while k <= BigInt(4) (p, q, k) = (k*k, BigInt(2)*k+BigInt(1), k+BigInt(1)) end This code compiles and runs in Julia 0.6, but in 1.0 produces ERROR: UndefVarError: k not defined . Did something change between versions? What's wrong with this code in Julia 1.0? 回答1: The answer by shadowtalker is correct. However, there is one important issue with this code that is worth adding some more explanation (and it was too long

Julia: How to profile parallel code

吃可爱长大的小学妹 提交于 2020-02-02 10:21:10
问题 Whats an appropriate way to profile parallel code in julia? When I run @profile foo(...) where foo is my function, I get julia> Profile.print() 1234 task.jl; anonymous; line: 23 4 multi.jl; remotecall_fetch; line: 695 2 multi.jl; send_msg_; line: 172 2 serialize.jl; serialize; line: 74 2 serialize.jl; serialize; line: 299 2 serialize.jl; serialize; line: 130 2 serialize.jl; serialize; line: 299 1 dict.jl; serialize; line: 369 1 serialize.jl; serialize_type; line: 278 1 serialize.jl; serialize