我们知道,对于MATLAB和JULIA 而言,预先赋值可以获得更快的运算速度,特别是MATLAB. 由于JULIA 经常用循还解决相关问题,预先赋值使用的频率相比MATLAB而言大大减小。不过,还是有一些地方,可能用到的,尽量不要使用CAT 操作,效率低下,速度慢得很。这个原则,还仅是对于MATLAB 还是JULIA,基本上都管用。

和MATLAB不同,MATLAB往往是使用zeros(n,m)的方法对数值进行赋值,但不等对混合类型(有字符串和数值混在一起的)进行赋值。

一、Julia的赋值:是对Array进行相应的操作而完成。

julia> a =Array(String,1,7) 
1x7 Array{String,2}:
 #undef  #undef  #undef  #undef  #undef  #undef  #undef

julia> b =Array(Float64,1,7)
1x7 Array{Float64,2}:
 0.0  0.0  0.0  0.0  0.0  0.0  0.0

julia> c=Array(Int64,1,7)
1x7 Array{Int64,2}:
 0  0  0  0  0  0  0

julia> h =Array(kbarData,10000) ; # 自定义类型kbarData的赋值,特别补充

有时,自定义类型还是很常见,对这个赋值有相当大的意义!

julia> e=Array(Any,3,7) 
3x7 Array{Any,2}:
 #undef  #undef  #undef  #undef  #undef  #undef  #undef
 #undef  #undef  #undef  #undef  #undef  #undef  #undef
 #undef  #undef  #undef  #undef  #undef  #undef  #undef

julia> f=Array(Int64,3,7)
3x7 Array{Int64,2}:
 0  0  0  0  0  0  0
 0  0  0  0  0  0  0
 0  0  0  0  0  0  0

julia> g=Array(String,3,7)
3x7 Array{String,2}:
 #undef  #undef  #undef  #undef  #undef  #undef  #undef
 #undef  #undef  #undef  #undef  #undef  #undef  #undef
 #undef  #undef  #undef  #undef  #undef  #undef  #undef

julia> c=Array(String,3,7)
3x7 Array{String,2}:
 #undef  #undef  #undef  #undef  #undef  #undef  #undef
 #undef  #undef  #undef  #undef  #undef  #undef  #undef
 #undef  #undef  #undef  #undef  #undef  #undef  #undef

注意:一维Array,就是一个Vector!

julia> g=Array{String,1}
Array{String,1}

julia> g=Array(String,1)
1-element Array{String,1}:
 #undef

julia> g=Array(String,7)
7-element Array{String,1}:
 #undef
 #undef
 #undef
 #undef
 #undef
 #undef
 #undef

总之,能赋值的就预先赋值,这样可能比push!大大提高效率。

二、 尽可能替代CAT函数

julia> table =["2014-9-17 15:19" 3260.0 700 3360.0 800 3620.0  12;"2014-9-18 15:
19" 3260.0 700 3360.0 800 3620.0  12]
2x7 Array{Any,2}:
 "2014-9-17 15:19"  3260.0  700  3360.0  800  3620.0  12
 "2014-9-18 15:19"  3260.0  700  3360.0  800  3620.0  12

julia> tab =["2014-9-19 15:19" 3260.0 700 3360.0 800 3620.0  12]
1x7 Array{Any,2}:
 "2014-9-17 15:19"  3260.0  700  3360.0  800  3620.0  12

julia> b=vcat(table,tab)

3x7 Array{Any,2}:
 "2014-9-17 15:19"  3260.0  700  3360.0  800  3620.0  12
 "2014-9-18 15:19"  3260.0  700  3360.0  800  3620.0  12
 "2014-9-19 15:19"  3260.0  700  3360.0  800  3620.0  12

julia> @time newtable =vcat(table,table,table);
elapsed time: 0.102088118 seconds (1039984 bytes allocated)

仅管vcat效率比较低,,因为象matlab或julia的矩阵值存储,事实上是按列来排位的,如果是vcat相当于需要精准地insert N个位置。

但是hcat效率还是很高的,因为,hcat操作相当于append在其中一块(比如,最后,最前,或某一列后),在查找定位时,至少开销少了多好,因此hcat要快。

因此,我们尽量避开cat操作。

我个人建议,在这里,可以使用循还,加快运算速度,当然,从功能上看,用cat操作简单省事,但代价是时间。

Julia对矩阵进行预先赋值相关推荐

  1. 基于MATLAB的矩阵及元素赋值

    *内容摘要 :该代码用于实现在MATLAB中矩阵及元素的赋值 *文件标识:无 *作 者: *完成日期:2019-3-10 *问题描述:给矩阵a赋值 >> a=[1 4 7;2 5 8; 3 ...

  2. Matlab矩阵间快速赋值方法

    目前还没见到网上用过这个简单的方式 A= [1 2 3; 4 5 6; 7 8 9] B = zeros(5,5) B(1:3, 2:4) = A     %将A赋值到B的第1行到3行,第2列岛4列, ...

  3. python对矩阵对角线进行赋值

  4. C# DirectX 开发2 - 定义一个矩阵和赋值

    接此, https://blog.csdn.net/bcbobo21cn/article/details/44890937 在C#版DirectX中,使用 Microsoft.DirectX.Matr ...

  5. matlab采用向量作为标号赋值的实质是同维矩阵的赋值

    matlab采用向量作为标号赋值的实质是完全相同维度矩阵的赋值 clear all;clc;close all; data=zeros(3,3); disp("初始矩阵:"); d ...

  6. code blocks代码性能分析_Julia系列教程13--如果写出高性能的Julia代码

    避免全局变量https://www.zhihu.com/video/1113506985873588224 code generationhttps://www.zhihu.com/video/111 ...

  7. Julia语言与其他语言的异同

    在编写Julia代码的过程中,会发现与其他语言有不少相似之处,例如Matlab.R或Python,但也有着明显的不同.通过与其他语言的对比,我们可以更加深入地理解Julia,也能够在熟悉其他语言的基础 ...

  8. 59. 螺旋矩阵 II(模拟)

    给你一个正整数 n ,生成一个包含 1 到 n2 所有元素,且元素按顺时针顺序螺旋排列的 n x n 正方形矩阵 matrix . 示例 1: 输入:n = 3 输出:[[1,2,3],[8,9,4] ...

  9. 矩阵化为行最简形矩阵计算器_[内附完整源码和文档] 基于C++的小型特殊计算器...

    1.设计内容 实现一个特殊的计算器,可以实现复数.有理数.矩阵和集合的特殊计算.程序可以实现复数.有理数的加.减.乘.除,可以实现矩阵的加法.减法和乘法运算,也可以实现集合的求交集.并集.子集的运算. ...

  10. matlab怎么给函数自变量赋值_MATLAB的变量及赋值

    变量及赋值 [n,m] n是行,m是列! 1.矩阵及其元素赋值 赋值就是把数赋予代表常量或标量的标识符.MATLAB中的变量或常量都代表矩阵,标量应看作1x1阶的矩阵.赋值语句的一般形式为: 变量=表 ...

最新文章

  1. Failed to load AppCompat ActionBar with unknown error
  2. 七段液晶数字识别-处理程序
  3. nginx服务器绑定域名和设置根目录的方法
  4. 【攻防世界010】re1-100
  5. 互联网1分钟 |1220
  6. [转载]轻松玩转LCD12864-基于AVR单片机的LCD12864串行显示
  7. CanvasRenderingContext2D(渲染上下文对象)
  8. python中xml模块_python学习第十五天-2(XML模块)
  9. 休息是为了更好的出发
  10. 软考信息系统项目管理师_项目范围管理1---软考高级之信息系统项目管理师011
  11. java虚拟机缩写为_(01-03)Java虚拟机缩写为。
  12. Netbackup7.5 access to the client was not allowed(59)问题解决
  13. 磊科nw336+linux驱动程序,磊科NW336无线网卡驱动程序
  14. 山东科技大学c语言答案,C语言练习题(山东科技大学吐血整理)
  15. 向股票,外汇,期货投资者推荐的好书
  16. python中class什么意思_python class是什么
  17. iOS 判断机型是否为iPhone Xs Max
  18. 百度招聘Android客服端(2)
  19. 大数据技术学习带来的思考
  20. php 图片处理慢,php图片处理

热门文章

  1. CentOS 6.7编写Shell脚本实现简单跳板机功能
  2. 为什么少有人在Windows电脑上安OS X?
  3. bay——RAC_ASM ORA-15001 diskgroup DATA does not exist or is not mounted.docx
  4. python collections模块(队列)
  5. 02-body标签中相关标签
  6. php调试利器之phpdbg
  7. 一句话讲清楚什么是JavaEE
  8. 转HashMap Hashtable区别
  9. 【BZOJ-1090】字符串折叠 区间DP + Hash
  10. SQL-基础学习4--聚集函数:AVG(),COUNT(),MAX(),MIN(),SUM();聚集不同值:DISTINCT