File: testmask.rb

package info (click to toggle)
ruby-narray 0.6.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 468 kB
  • sloc: ansic: 4,498; ruby: 1,329; python: 91; makefile: 7
file content (40 lines) | stat: -rw-r--r-- 675 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require "narray"

a = NArray.byte(10)
a[2..4] = 1
p a.class, a.count_true, a.count_false

begin
   a = NArray.float(10)
   a[2..4] = 1
   p a.class, a.count_true, a.count_false
rescue
   print a.class," -- Exception raised as expected. The message was: ", $!,"\n"
end

#-------------------
print "\n--- test masking (float) ---\n"

a = NArray.float(5,3).indgen!
b = (a-2)*2
c = a.lt(b)
p c, c.typecode

p a, b, a.mask( c ), a[c]

#a[c] = ( NArray.int(c.length).indgen!+100 )
#p a

a[c] = 10000
p a

#-------------------
print "\n--- test masking (complex) ---\n"
p a = NArray.complex(5).indgen! + Complex::I

m = NArray.byte(5)
m[true] = [0,0,1,1,0]

p a[m]
a[m] = 100.0
p a