Ruby语言做大型数学运算怎么样?

Python018

Ruby语言做大型数学运算怎么样?,第1张

这种脚本语言做大型计算,计算能力肯定是不太够的,一般都依赖于其它语言编写的高性能计算的库,比如python就有numpy/scipy/pandas/matplotlib等一系列库,这使得python比较适合进行大型科学计算,ruby也有相当的库sciruby,不过成熟度还不太够,sciruby官网上的说法是,这个库已经经过了测试,但是还没有经过实战的检验,在使用中要有可能会遇到bug的心理预期。原话如下:

Word to the wise: These gems have been tested, but are not battle-hardened. If you’re thinking of using NMatrix (or other SciRuby components) to write mission critical code, such as for a self-driving car or controlling an ARKYD 100 satellite, you should expect to encounter a few bugs — and be prepared for them.

for i in 1..9

for j in 1..i

print j

print " X "

print i

print " = "

print j*i

print " "

if j==i

print "\n"

end

end

end

这个怎么说好呢,它们无非就是一些运算符而已,每个符号的用法也有很多种,具体怎么用可以通过看书、看例子来学习,没必要一下记住那么多。

比如:

%#取余运算,如8%3=2

{}#可用在输出,如输出y的值:puts"#{y}",也可用在Hash表如 $R_Key_Hash = {}

. #一般表示某种属性或方法,如对于一个窗口,self.x = 0 表示这个窗口的x坐标为0。

又如

Class Person

def Hello

puts "Hello,my name is Tom."

end

end

p=Person.new

p.Hello #执行这个程序就会输出 Hello,my name is Tom.

? #表判断,如opacity = black_color ? 255 : 128,这个意思是如果是黑色,就不透明,否则为128

, #逗号在数组中较常见,如a = ["1","2","3"],数组a的三个元素依次是1,2,3

‘ #这个在对文件的操作比较常见,如下例:

if Dir.glob('txt').size == 0 #如果文件夹txt不存在

Dir.mkdir('./txt') #那么生成一个名字叫txt的文件夹

end

! # 表示 非 如 if x != 2 表示如果x不等于2

: #这个可能用在属性里

如:

class Game_Picture

attr_reader :number # 图片编号

attr_reader :origin # 原点

attr_reader :x# X 坐标

attr_reader :y# Y 坐标

attr_reader :tone # 色调

attr_reader :angle# 旋转角度

end

#分号的话,一般是写程序每行结束才用到,但其实ruby的每行结束是可以不用分号的,回车换行就行,我也只是在用Interactive Ruby编译器时才会用分号

从我上边的回答可看出,基本每个符号都用几种用法,平时多学习,多积累就好了