当前位置:网站首页>Julia常见符号意思
Julia常见符号意思
2022-08-09 10:52:00 【1nsights】
::, 声明变量的类型
::符号来声明(或者标注)变量类型,使用 :: 运算符在函数声明中指定返回类型。 这可以将返回值转换为指定的类型。
julia> function g(x, y)::Int8
return x * y
end;
julia> typeof(g(1, 2))
Int8
不完全初始化
julia> mutable struct SelfReferential
obj::SelfReferential
end
<:运算符代表:左边是右边的子类型,它可以在声明的时候使用,也可以用来做类型判断
<:,sub-type
abstract type Person
end
abstract type Musician <: Person
end
->, 创建一个匿名函数
用在Anonymous Functions中,类似于python里面的lambda
julia> x -> x^2 + 2x - 1
#1 (generic function with 1 method)
julia> function (x)
x^2 + 2x - 1
end
#3 (generic function with 1 method)
定义一个x平方的函数,可以是:
square(x) = x^2
也可以是使用匿名函数的形式:
square = x -> x^2
上面这段语句的意思是:定义一个x的函数,并返回x的平方值
匿名函数的扩展
有时候,会在一个函数的输入中,有匿名函数的定义,比如:quadgk(x->f(x,42,4), 3, 4),这代表的含义是什么呢?
Aurelio Amerio大神的解释通俗易懂,以下面两种函数定义的形式为例:
有一个函数f,有三个变量x,y,z,如果固定两个变量y,z,求f对x的积分,就可以写成下面的形式:
using Pkg
Pkg.add("QuadGK")
using QuadGK
f(x,y,z) = (x^2 + 2y)*z
quadgk(x->f(x,42,4), 3, 4)
等效于:
using Pkg
Pkg.add("QuadGK")
using QuadGK
f(x,y,z) = (x^2 + 2y)*z
arg(x) = f(x,42,4)
quadgk(arg, 3, 4)
。。。未完待续
如果对您有启发,欢迎您给我点赞支持!
Reference
https://blog.csdn.net/m0_37696990/article/details/82262060
https://techytok.com/lesson-functions/
https://docs.julialang.org/en/v1/manual/functions/index.html#man-anonymous-functions-1
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接https://blog.csdn.net/weixin_44217573/article/details/114693588
边栏推荐
- 985毕业,工作3年,分享从阿里辞职到了国企的一路辛酸和经验
- 一键完成物联网产品注册,快速体验在线调试设备
- shell脚本实战(第2版)/人民邮电出版社 脚本2 验证输入:仅限字母和数字
- 【原创】JPA中@PrePersist和@PreUpdate的用法
- pip common commands and changing source files
- The torch. The stack () official explanation, explanation and example
- 1007 Maximum Subsequence Sum (25分)
- Unix Environment Programming Chapter 14 14.8 Memory Mapped I/O
- 无重复字符的最长子串
- autogluon安装,使用指南,代码
猜你喜欢

Tensorflow realize parameter adjustment of linear equations

MySQL查询性能优化七种武器之索引潜水

性能测试(03)-JDBC Request

图片查看器viewer

pytorch widedeep文档

【报错记录】解决华擎J3455-ITX不插显示器无法开机的问题

Netscope: Online visualization tool for neural network structures

性能测试(04)-表达式和业务关联-JDBC关联

Shell script combat (2nd edition) / People's Posts and Telecommunications Press Script 2 Validate input: letters and numbers only

shap库源码和代码实现
随机推荐
1005 Spell It Right (20分)
1006 Sign In and Sign Out (25分)
TensorFlow:NameError: name ‘input_data’ is not defined
Unix Environment Programming Chapter 14 14.4 I/O Multiplexing
focusablejs
1003 Emergency (25分)
C语言统计不同单词数
程序员的专属浪漫——用3D Engine 5分钟实现烟花绽放效果
uni-app 自带的picker封装一个日期-时间选择器
The complete grammar of CSDN's markdown editor
unix系统编程 第十五章 15.2管道
Product Quantization (PQ)
Oracle数据库常用函数总结
微信小程序——天气查询
乘积量化(PQ)
日期工具类
MNIST机器学习入门
Missing URI template variable ‘employeeNumber‘ for method parameter of type String
Unix System Programming Chapter 15 15.2 Pipes
彻底理解工厂模式