很抱歉,这个基本问题是,谷歌搜索到目前为止并不太有用。
我是个新手。我想问一问,是否有可能让Julia在作业中自动检测不兼容的类型。
例如,当我写
julia> x=10;
julia> typeof(x)
Int32
julia> y=9.0;
julia> typeof(y)
Float64
julia> x=y // I'd like this to generate an error or a warning at least
9.0
julia> typeof(x) // do not want automatic type
我想执行以下代码,当我在Windows 10上将每一行输入到我的朱莉娅控制台时,它都能很好地工作,但是由于LinearAlgebra.Adjoint{Float64,Array{Float64,2}}类型不匹配而抛出一个错误(我随后的代码期望Array{Float64,2})。
这是代码:
x = [0.2, 0.1, 0.2]
y = [-0.5 0.0 0.5]
fx = x * y
fy = fx'
return fx::Array{Float64,2}, fy::Array{Float64,2}
有一个TypeError,因为fy似乎是LinearAlgebra.Adjoi
我知道可以使用convert函数将Float64转换为Int64。不幸的是,当将convert应用于2维数组时,它不起作用。
julia> convert(Int64, 2.0)
2
julia> A = [1.0 2.0; 3.0 4.0]
2x2 Array{Float64,2}:
1.0 2.0
3.0 4.0
julia> convert(Int64, A)
ERROR: `convert` has no method matching convert(::Type{Int64}, ::Array{Float64,2
})
in convert at b
我有一个带有标题的函数
integrateL(f, lb::SArray{Tuple{S},Float64,1, S} where S<:Integer, ub::SArray{Tuple{S},Float64,1, S} where S<:Integer, y::Float64)
return nothing
end
我不分享问题的内容,因为问题不在里面,而且会让人感到困惑。这个问题是可以重复的。该函数在转换变量后与HCubature.jl包进行半无限维积分.在参数中,我按照包文档中的建议使用StaticArrays来实现性能。若要复制错误,请执行以下操作。
lb = z
下面是我的代码: using Plots
using SpecialFunctions
using QuadGK
kappa = 1
B = 1
xi = (kappa/B)^4
function correlation(x)
quadgk(q -> q * SpecialFunctions.besselj0(x*q)/(q^4 + xi), 0, 1e6)[1]/kappa
end
r = range(-20, 20, length = 1001)
plot(r, correlation(r)) 我在Bessel函数上得到一个错误。我知道这个参数就是问题所在,它的格
我试图用c生成mandlebrot集,但是得到了一些不正确的输出。。。这个密码怎么了?
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "dislin.h"
//generate jula set data for particular constant
static long double const_x;
static long double const_y;
static long double r_lim;
//handle complex num
我有一个颜色数组,我想转换成一个数字矩阵:
using Colors
cols = [RGB{Float64}(rand(), rand(), rand()) for i in 1:6]
6-element Array{ColorTypes.RGB{Float64},1}:
RGB{Float64}(0.836012,0.505908,0.249548)
RGB{Float64}(0.383172,0.105153,0.361422)
RGB{Float64}(0.680616,0.974232,0.942787)
RGB{Float64}(0.804829,0.825503,0.99022
请看一看下列MWE:
julia> function foo()
# do something
R = rand(3,3)
t = rand(3)
y = [ R t;
0 0 0 1]
# do something
end
foo (generic function with 1 method)
julia> @code_warntype foo()
Variables:
#self#::#foo
R::Array{Float64,2}
t:
type ExtendedJumpArray{T,T2} <: AbstractArray{Float64,1}
u::T
jump_u::T2
end
Base.length(A::ExtendedJumpArray) = length(A.u)
Base.size(A::ExtendedJumpArray) = (length(A),)
function Base.getindex(A::ExtendedJumpArray,i::Int)
i <= length(A.u) ? A.u[i] : A.jump_u[i-length(A.u)]
end
functio
我设法找到了将RGB转换为XY的代码。不能让它以相反的方式工作。
我已经查看了飞利浦色调软件开发工具包
我找到了这段javascript代码:,并将其转换为c#,但它并不能像预期的那样工作。我想我的数学还不够强。请给我建议。
public class PhilipsHueRgbObject
{
public int Red { get; set; }
public int Green { get; set; }
public int Blue { get; set; }
}
public static
我正在尝试将python脚本转换为Julia。我正在检查以确保我正在以最优的方式执行这段代码。请参阅下列代码:
julia> a = [1,2,3,4,5]
5-element Array{Int64,1}:
1
2
3
4
5
julia> if 1 in a
print("1 is in a")
end
1 is in a
julia> if 6 not in a
print("6 not in a")
end
ERROR: TypeError: non-b
代码- Quasi Newton Problem 这是拟牛顿问题的代码。因此,我得到了一个错误 MethodError: no method matching isless(::Matrix{Float64}, ::Matrix{Float64})
Closest candidates are:
isless(::Any, ::Missing) at missing.jl:88
isless(::Missing, ::Any) at missing.jl:87
Stacktrace:
[1] <(x::Matrix{Float64}, y::Matrix{Float64}
在Fortran中,我们知道我们可以在模块中定义一个全局变量(使用私有属性),这样我们就可以使用模块中的子程序来设置或更改该变量的值。见下文,
module Mod
integer, parameter :: r8=selected_real_kind(15,9)
real(kind=r8), private, save :: var
contains
subroutine f(x)
real(kind=r8) :: x
var = 2.0_r8*x
end subroutine f
end
正如我们所看到的,我们可以调用f(x)并将模块中的var设置为2x。
在朱莉娅看来,
module M
我是Julia的新手,我有一个Python函数,我想在Julia中使用它。基本上,函数所做的是接受一个dataframe (作为numpy ndarray传递)、一个筛选值和一个列索引列表(来自数组),并使用statsmodels中的包运行逻辑回归。到目前为止,我已经尝试过:
using PyCall
py"""
import pandas as pd
import numpy as np
import random
import statsmodels.api as sm
import itertools
def reg_frac(state, ind_vars):
我有一个在不同行上执行各种计算的数据帧。我尝试将数据帧写入csv输出,但一直收到以下错误:ArgumentError: `nothing` should not be printed; use `show`, `repr`, or custom output instead. 代码如下: filename = "Alldata.csv"
CSV.write(filename, bf) 下面是堆栈跟踪: [2] print_to_string(::Nothing) at .\strings\io.jl:123
[3] string(::Nothing) at .\strin