Class: NArrayMiss
- Inherits:
-
Object
- Object
- NArrayMiss
- Includes:
- NMMath
- Defined in:
- lib/narray_miss.rb,
lib/narray_miss.rb
Constant Summary collapse
- BYTE =
Class Constants
— NArrayMiss::BYTE
type code for 1 byte unsigned integer.— NArrayMiss::SINT
type code for 2 byte signed integer.— NArrayMiss::INT
type code for 4 byte signed integer.— NArrayMiss::SFLOAT
type code for single precision float.— NArrayMiss::FLOAT
type code for double precision float.— NArrayMiss::SCOMPLEX
type code for single precision complex.— NArrayMiss::COMPLEX
type code for double precision complex.— NArrayMiss::OBJECT
type code for Ruby object.go back to ((<Index>))
NArray::BYTE
- SINT =
NArray::SINT
- INT =
NArray::INT
- SFLOAT =
NArray::SFLOAT
- FLOAT =
NArray::FLOAT
- SCOMPLEX =
NArray::SCOMPLEX
- COMPLEX =
NArray::COMPLEX
- OBJECT =
NArray::OBJECT
Class Method Summary collapse
- .[](*arg) ⇒ Object
- .__new__ ⇒ Object
- ._load(o) ⇒ Object
- .byte(*arg) ⇒ Object
- .complex(*arg) ⇒ Object
- .float(*arg) ⇒ Object
- .int(*arg) ⇒ Object
-
.new(*arg) ⇒ Object
Class Methods — NArrayMiss.new(typecode, size, …) create ((NArrayMiss)) of ((|typecode|)).
- .object(*arg) ⇒ Object
- .scomplex(*arg) ⇒ Object
- .sfloat(*arg) ⇒ Object
- .sint(*arg) ⇒ Object
- .to_nam(*arg) ⇒ Object
- .to_nam_no_dup(*arg) ⇒ Object
Instance Method Summary collapse
-
#-@ ⇒ Object
Arithmetic operator — NArrayMiss#-@ — NArrayMiss#+(other) — NArrayMiss#-(other) — NArrayMiss#*(other) — NArrayMiss#/(other) — NArrayMiss#%(other) — NArrayMiss#**(other) — NArrayMiss#abs — NArrayMiss#add!(other) — NArrayMiss#sbt!(other) — NArrayMiss#mul!(other) — NArrayMiss#div!(other) — NArrayMiss#mod!(other) — NArrayMiss#mul_add(other, dim, …).
-
#[](*arg) ⇒ Object
Slicing Array — NArrayMiss#[](index) return the value at [((|index|))].
- #[]=(*arg) ⇒ Object
- #__clone__ ⇒ Object
- #_dump(limit) ⇒ Object
- #abs ⇒ Object
-
#accum(*arg) ⇒ Object
Statistics — NArrayMiss#sum(dim, … [“min_count”=>i]) return summation of elements in specified dimensions.
- #all? ⇒ Boolean
- #all_invalid ⇒ Object
- #all_valid ⇒ Object
- #all_valid? ⇒ Boolean
- #angle ⇒ Object
- #any? ⇒ Boolean
- #any_valid? ⇒ Boolean
- #clone ⇒ Object
- #coerce(x) ⇒ Object
- #collect(&blk) ⇒ Object
- #collect! ⇒ Object
- #complex? ⇒ Boolean
- #conj ⇒ Object
-
#count_false ⇒ Object
Boolean and mask related (only for byte, sint and int) — NArrayMiss#count_false return the number of elements whose value==0 and valid.
- #count_invalid(*arg) ⇒ Object
- #count_true ⇒ Object
- #count_valid(*arg) ⇒ Object
-
#dim ⇒ Object
NArrayMiss information — NArrayMiss#dim return the dimension which is the number of indices.
- #dup ⇒ Object
-
#each ⇒ Object
Iteration — NArrayMiss#each{|x| …} — NArrayMiss#each_valid{|x| …} — NArrayMiss#each_valid_with_index{|x,i| …} — NArrayMiss#collect{|x| …} — NArrayMiss#collect{|x| …}.
- #each_valid ⇒ Object
- #each_valid_with_index ⇒ Object
- #get_array ⇒ Object
- #get_array! ⇒ Object
- #get_mask ⇒ Object
- #get_mask! ⇒ Object
- #hton ⇒ Object (also: #ntoh)
- #htov ⇒ Object (also: #vtoh)
- #im ⇒ Object
- #imag ⇒ Object
- #imag=(arg) ⇒ Object
- #inspect ⇒ Object
-
#integer? ⇒ Boolean
Others — NArrayMiss#integer? return true if ((NArrayMiss)) is byte, sint or int, else false.
- #mask(arg) ⇒ Object
- #mean(*arg) ⇒ Object
- #median(*arg) ⇒ Object
- #mul_add(*arg) ⇒ Object
- #newdim(*arg) ⇒ Object (also: #rewrank)
- #newdim!(*arg) ⇒ Object (also: #rewrank!, #rewrank=)
- #none? ⇒ Boolean
- #none_valid? ⇒ Boolean (also: #all_invalid?)
- #not ⇒ Object
- #randomn ⇒ Object
- #rank ⇒ Object
- #rank_total(*arg) ⇒ Object
-
#real ⇒ Object
Complex compound number (only for scomplex and complex) — NArrayMiss#real — NArrayMiss#imag — NArrayMiss#conj — NArrayMiss#angle — NArrayMiss#imag=(other) — NArrayMiss#im.
- #reshape(*arg) ⇒ Object
-
#reshape!(*arg) ⇒ Object
(also: #shape=)
Changing Shapes of indices — NArrayMiss#reshape!(size, …) change shape of array.
- #set_invalid(*pos) ⇒ Object (also: #invalidation)
- #set_mask(mask) ⇒ Object
- #set_missing_value(val) ⇒ Object
- #set_missing_value!(val) ⇒ Object
-
#set_valid(*pos) ⇒ Object
(also: #validation)
Mask and missing value — NArrayMiss#set_valid(index) validate element at ((|index|)).
- #set_without_validation(*arg) ⇒ Object
- #shape ⇒ Object
- #size ⇒ Object (also: #total, #length)
- #slice(*arg) ⇒ Object
- #stddev(*arg) ⇒ Object
-
#swap_byte ⇒ Object
Byte swap — NArrayMiss#swap_byte swap byte order.
- #to_a ⇒ Object
- #to_na(*arg) ⇒ Object
- #to_na!(*arg) ⇒ Object
- #to_s ⇒ Object
- #to_string ⇒ Object
- #to_type(typecode) ⇒ Object
-
#transpose(*arg) ⇒ Object
Transpose — NArrayMiss#transpose(dim0, dim1, …) transpose array.
- #typecode ⇒ Object
- #valid? ⇒ Boolean
- #where ⇒ Object
- #where2 ⇒ Object
-
#~@ ⇒ Object
Bitwise operator (only for byte, sint and int) — NArrayMiss#~@ — NArrayMiss#&(other) — NArrayMiss#|(other) — NArrayMiss#^(other).
Class Method Details
.[](*arg) ⇒ Object
147 148 149 |
# File 'lib/narray_miss.rb', line 147 def self.[](*arg) NArrayMiss.to_nam(NArray[*arg]) end |
.__new__ ⇒ Object
73 |
# File 'lib/narray_miss.rb', line 73 alias :__new__ :new |
._load(o) ⇒ Object
1248 1249 1250 1251 1252 1253 |
# File 'lib/narray_miss.rb', line 1248 def self._load(o) ary, mask = Marshal::load(o) ary = NArray._load(ary) mask = NArray._load(mask) NArrayMiss.to_nam_no_dup(ary,mask) end |
.byte(*arg) ⇒ Object
123 124 125 |
# File 'lib/narray_miss.rb', line 123 def self.byte(*arg) NArrayMiss.new(BYTE,*arg) end |
.complex(*arg) ⇒ Object
141 142 143 |
# File 'lib/narray_miss.rb', line 141 def self.complex(*arg) NArrayMiss.new(COMPLEX,*arg) end |
.float(*arg) ⇒ Object
135 136 137 |
# File 'lib/narray_miss.rb', line 135 def self.float(*arg) NArrayMiss.new(FLOAT,*arg) end |
.int(*arg) ⇒ Object
129 130 131 |
# File 'lib/narray_miss.rb', line 129 def self.int(*arg) NArrayMiss.new(INT,*arg) end |
.new(*arg) ⇒ Object
Class Methods
— NArrayMiss.new(typecode, size, …)
create (({NArrayMiss})) of ((|typecode|)).
All elements are initialized with 0.
— NArrayMiss.byte(size, …)
same as NArrayMiss.new(NArrayMiss::BYTE, ((|size|)), ...).
— NArrayMiss.sint(size, …)
same as NArrayMiss.new(NArrayMiss::SINT, ((|size|)), ...).
— NArrayMiss.int(size, …)
same as NArrayMiss.new(NArrayMiss::INT, ((|size|)), ...).
— NArrayMiss.sfloat(size, …)
same as NArrayMiss.new(NArrayMiss::SFLOAT, ((|size|)), ...).
— NArrayMiss.float(size, …)
same as NArrayMiss.new(NArrayMiss::FLOAT, ((|size|)), ...).
— NArrayMiss.scomplex(size, …)
same as NArrayMiss.new(NArrayMiss::SCOMPLEX, ((|size|)), ...).
— NArrayMiss.complex(size, …)
same as NArrayMiss.new(NArrayMiss::COMPLEX, ((|size|)), ...).
— NArrayMiss.object(size, …)
same as NArrayMiss.new(NArrayMiss::OBJECT, ((|size|)), ...).
— NArrayMiss[](value, …)
create (({NArrayMiss})) form [((|value|)), ...].
— NArrayMiss.to_nam(array [,mask])
create (({NArrayMiss})) from ((|array|)).
((|array|)) must be (({Array})) or (({NArray})).
— NArrayMiss.to_nam_no_dup(array [,mask])
convert from ((|array|)) to (({NArrayMiss})).
go back to ((<Index>))
118 119 120 121 122 |
# File 'lib/narray_miss.rb', line 118 def self.new(*arg) array = NArray.new(*arg) mask = NArray.byte(*arg[1..-1]) __new__(array, mask) end |
.object(*arg) ⇒ Object
144 145 146 |
# File 'lib/narray_miss.rb', line 144 def self.object(*arg) NArrayMiss.new(OBJECT,*arg) end |
.scomplex(*arg) ⇒ Object
138 139 140 |
# File 'lib/narray_miss.rb', line 138 def self.scomplex(*arg) NArrayMiss.new(SCOMPLEX,*arg) end |
.sfloat(*arg) ⇒ Object
132 133 134 |
# File 'lib/narray_miss.rb', line 132 def self.sfloat(*arg) NArrayMiss.new(SFLOAT,*arg) end |
.sint(*arg) ⇒ Object
126 127 128 |
# File 'lib/narray_miss.rb', line 126 def self.sint(*arg) NArrayMiss.new(SINT,*arg) end |
.to_nam(*arg) ⇒ Object
185 186 187 188 189 190 191 192 193 194 |
# File 'lib/narray_miss.rb', line 185 def self.to_nam(*arg) if !(Numeric===arg[0]) && Array===arg[0] && !arg[0].is_a?(NArray) raise "first argument must be Numeric, NArray or Array" end arg[0] = arg[0].dup if !(Numeric===arg[0]) if arg.length==2 && !(Numeric===arg[1]) && arg[1].class!=TrueClass && arg[1].class!=FalseClass then arg[1] = arg[1].dup end NArrayMiss.to_nam_no_dup(*arg) end |
.to_nam_no_dup(*arg) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/narray_miss.rb', line 150 def self.to_nam_no_dup(*arg) if arg.length > 2 || arg.length==0 then raise("NArrayMiss.to_nar( array [,mask]] )") end array = arg[0] if Numeric===array then array = NArray[array] end if Array===array then array = NArray.to_na(array) end if !array.is_a?(NArray) then raise("argument must be Numeric, NArray or Array") end if arg.length==2 then mask = arg[1] if Numeric===mask then mask = [mask] end if Array===mask then mask = NArray.to_na(mask).ne(0) end if mask.class == FalseClass then mask = NArray.byte(*array.shape) end if mask.class == TrueClass then mask = NArray.byte(*array.shape).fill(1) end if !(NArray===mask && mask.typecode==BYTE) then raise("mask must be Numeric, Array, true, false or NArray(byte)") end if mask.length!=array.length raise "mask.length must be same as array.length" end else mask = NArray.byte(*array.shape).fill(1) end __new__(array,mask) end |
Instance Method Details
#-@ ⇒ Object
Arithmetic operator
— NArrayMiss#-@ — NArrayMiss#+(other) — NArrayMiss#-(other) — NArrayMiss#*(other) — NArrayMiss#/(other) — NArrayMiss#%(other) — NArrayMiss#**(other) — NArrayMiss#abs — NArrayMiss#add!(other) — NArrayMiss#sbt!(other) — NArrayMiss#mul!(other) — NArrayMiss#div!(other) — NArrayMiss#mod!(other) — NArrayMiss#mul_add(other, dim, …)
367 368 369 370 371 |
# File 'lib/narray_miss.rb', line 367 def -@ array = @array.dup array[@mask] = -@array[@mask] NArrayMiss.to_nam_no_dup(array, @mask.dup) end |
#[](*arg) ⇒ Object
Slicing Array
— NArrayMiss#[](index)
return the value at [((|index|))].
((|index|)) must be (({Integer, Range, Array, true})).
Index order is FORTRAN type.
— NArrayMiss#slice(index)
same as (({NArrayMiss#[]})) but keeps the rank of original array by not elimiting dimensions whose length became equal to 1 (which (({NArrayMiss#[]})) dose).
This is not the case with the 1-dimensional indexing and masking.
— NArrayMiss#set_without_validation(index,value)
replace elements at ((|index|)) by ((|value|)).
— NArrayMiss#[]=(index, value)
replace elements at ((|index|)) by ((|value|)) and
make replaced elements valid.
262 263 264 265 266 267 268 269 |
# File 'lib/narray_miss.rb', line 262 def [](*arg) obj = @array[*arg] if Numeric===obj return obj else return NArrayMiss.to_nam_no_dup(obj,@mask[*arg]) end end |
#[]=(*arg) ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/narray_miss.rb', line 297 def []=(*arg) self.set_without_validation(*arg) if arg[-1].class != NArrayMiss && arg[-1] then if arg.length==1 then @mask=1 else @mask[*arg[0..-2]] = 1 end end return self end |
#__clone__ ⇒ Object
1162 |
# File 'lib/narray_miss.rb', line 1162 alias __clone__ clone |
#_dump(limit) ⇒ Object
1245 1246 1247 |
# File 'lib/narray_miss.rb', line 1245 def _dump(limit) Marshal::dump([@array._dump(nil),@mask._dump(nil)]) end |
#abs ⇒ Object
387 388 389 390 391 |
# File 'lib/narray_miss.rb', line 387 def abs array = @array.dup array[@mask] = @array[@mask].abs NArrayMiss.to_nam_no_dup(array, @mask.dup) end |
#accum(*arg) ⇒ Object
Statistics
— NArrayMiss#sum(dim, … [“min_count”=>i])
return summation of elements in specified dimensions.
Elements at which the number of elements for summation is less than ((|i|)) is invalid.
— NArrayMiss#accum(dim, …)
same as (({NArrayMiss#sum})) but not elimiting dimensions whose length became equal to 1.
— NArrayMiss#min(dim, …)
return minimum in specified dimensions.
Elements at which the number of valid elements in the dimension is less than ((|i|)) is invalid.
— NArrayMiss#max(dim, …)
return maximum in specified dimensions.
Elements at which the number of valid elements in the dimension is less than ((|i|)) is invalid.
— NArrayMiss#median(dim, …)
return median in specified dimensions.
Elements at which the number of valid elements in the dimension is less than ((|i|)) is invalid.
— NArrayMiss#mean(dim, …)
return mean of elements in specified dimensions.
Elements at which the number of elements for then mean is less than ((|i|)) is invalid.
— NArrayMiss#stddev(dim, …)
return standard deviation of elements in specified dimensions.
Elements at which the number of elements for calculation the standard deviation is less than ((|i|)) is invalid.
519 520 521 522 523 524 525 526 527 528 |
# File 'lib/narray_miss.rb', line 519 def accum(*arg) if @mask.count_true == 0 then return nil else array = @array.dup array[@mask.not] = 0 return NArrayMiss.to_nam_no_dup(array.accum(*arg), @mask.to_type(NArray::INT).accum(*arg).ne(0)) end end |
#all? ⇒ Boolean
912 913 914 |
# File 'lib/narray_miss.rb', line 912 def all? @array[@mask].all? end |
#all_invalid ⇒ Object
1049 1050 1051 1052 |
# File 'lib/narray_miss.rb', line 1049 def all_invalid @mask[true]=0 self end |
#all_valid ⇒ Object
1045 1046 1047 1048 |
# File 'lib/narray_miss.rb', line 1045 def all_valid @mask[true]=1 self end |
#all_valid? ⇒ Boolean
1109 1110 1111 |
# File 'lib/narray_miss.rb', line 1109 def all_valid? @mask.all? end |
#angle ⇒ Object
951 952 953 |
# File 'lib/narray_miss.rb', line 951 def angle NArrayMiss.to_nam_no_dup(@array.angle,@mask) end |
#any? ⇒ Boolean
915 916 917 |
# File 'lib/narray_miss.rb', line 915 def any? @array[@mask].any? end |
#any_valid? ⇒ Boolean
1116 1117 1118 |
# File 'lib/narray_miss.rb', line 1116 def any_valid? @mask.any? end |
#clone ⇒ Object
1163 1164 1165 1166 1167 1168 |
# File 'lib/narray_miss.rb', line 1163 def clone obj = __clone__ obj.set_array(@array.clone) obj.set_mask(@mask.clone) return obj end |
#coerce(x) ⇒ Object
1170 1171 1172 1173 1174 1175 1176 1177 1178 |
# File 'lib/narray_miss.rb', line 1170 def coerce(x) if Numeric===x then return [NArrayMiss.new(NArray[x].typecode,*self.shape).fill(x),self] elsif x.class==Array || x.class==NArray then return [NArrayMiss.to_nam(x), self] else raise("donnot know how to cange #{x.class} to NArrayMiss") end end |
#collect(&blk) ⇒ Object
864 865 866 |
# File 'lib/narray_miss.rb', line 864 def collect(&blk) self.dup.collect!(&blk) end |
#collect! ⇒ Object
858 859 860 861 862 863 |
# File 'lib/narray_miss.rb', line 858 def collect! for i in 0..self.total-1 self[i] = yield(self[i]) end self end |
#complex? ⇒ Boolean
1153 1154 1155 |
# File 'lib/narray_miss.rb', line 1153 def complex? @array.complex? end |
#conj ⇒ Object
948 949 950 |
# File 'lib/narray_miss.rb', line 948 def conj NArrayMiss.to_nam_no_dup(@array.conj,@mask) end |
#count_false ⇒ Object
Boolean and mask related (only for byte, sint and int)
— NArrayMiss#count_false
return the number of elements whose value==0 and valid.
— NArrayMiss#count_true
return the number of elements whose value!=0 and valid.
— NArrayMiss#mask(mask)
return (({NArrayMiss#get_mask!&((|mask|))})).
— NArrayMiss#all?
return true if all the valid elements are not 0, else false.
— NArrayMiss#any?
return true if any valid element is not 0, else false.
— NArrayMiss#none?
return true if none of the valid elements is not 0, else false.
— NArrayMiss#where
return (({NArray})) of indices where valid elements are not 0.
— NArrayMiss#where2
return (({Array})) including two (({NArray}))s of indices,
where valid elements are not 0, and 0, respectively.
890 891 892 893 894 895 896 |
# File 'lib/narray_miss.rb', line 890 def count_false if @array.typecode==BYTE then return @array.count_false-@mask.count_false else raise("cannot count_true NArrayMiss except BYTE type") end end |
#count_invalid(*arg) ⇒ Object
1127 1128 1129 1130 1131 1132 1133 1134 |
# File 'lib/narray_miss.rb', line 1127 def count_invalid(*arg) if arg.length==0 then return @mask.count_false else return NArray.int(*@mask.shape).fill(1).sum(*arg)- @mask.to_type(NArray::INT).sum(*arg) end end |
#count_true ⇒ Object
897 898 899 900 901 902 903 |
# File 'lib/narray_miss.rb', line 897 def count_true if @array.typecode==BYTE then return (@array&@mask).count_true else raise("cannot count_true NArrayMiss except BYTE type") end end |
#count_valid(*arg) ⇒ Object
1120 1121 1122 1123 1124 1125 1126 |
# File 'lib/narray_miss.rb', line 1120 def count_valid(*arg) if arg.length==0 then return @mask.count_true else return @mask.to_type(NArray::INT).sum(*arg) end end |
#dim ⇒ Object
NArrayMiss information
— NArrayMiss#dim
return the dimension which is the number of indices.
— NArrayMiss#rank
same as (({NArrayMiss#dim})).
— NArrayMiss#shape
return the (({Array})) of sizes of each index.
— NArrayMiss#size
return the number of total elements.
— NArrayMiss#total
alias to size
— NArrayMiss#length
alias to size
— NArrayMiss#rank_total
return the number of total of the shape.
— NArrayMiss#typecode
return the typecode.
222 223 224 |
# File 'lib/narray_miss.rb', line 222 def dim @array.dim end |
#dup ⇒ Object
1158 1159 1160 |
# File 'lib/narray_miss.rb', line 1158 def dup NArrayMiss.to_nam(@array,@mask) end |
#each ⇒ Object
Iteration
— NArrayMiss#each{|x| …} — NArrayMiss#each_valid{|x| …} — NArrayMiss#each_valid_with_index{|x,i| …} — NArrayMiss#collect{|x| …} — NArrayMiss#collect{|x| …}
843 844 845 846 847 |
# File 'lib/narray_miss.rb', line 843 def each for i in 0..self.total-1 yield(@array[i]) end end |
#each_valid ⇒ Object
848 849 850 851 852 |
# File 'lib/narray_miss.rb', line 848 def each_valid for i in 0..self.total-1 yield(@array[i]) if @mask[i] end end |
#each_valid_with_index ⇒ Object
853 854 855 856 857 |
# File 'lib/narray_miss.rb', line 853 def each_valid_with_index for i in 0..self.total-1 yield(@array[i],i) if @mask[i] end end |
#get_array ⇒ Object
1094 1095 1096 |
# File 'lib/narray_miss.rb', line 1094 def get_array @array.dup end |
#get_array! ⇒ Object
1091 1092 1093 |
# File 'lib/narray_miss.rb', line 1091 def get_array! @array end |
#get_mask ⇒ Object
1088 1089 1090 |
# File 'lib/narray_miss.rb', line 1088 def get_mask @mask.dup end |
#get_mask! ⇒ Object
1085 1086 1087 |
# File 'lib/narray_miss.rb', line 1085 def get_mask! @mask end |
#hton ⇒ Object Also known as: ntoh
982 983 984 |
# File 'lib/narray_miss.rb', line 982 def hton NArray.to_nam(@array.hton,@mask.hton) end |
#htov ⇒ Object Also known as: vtoh
986 987 988 |
# File 'lib/narray_miss.rb', line 986 def htov NArray.to_nam(@array.htov,@mask.htov) end |
#im ⇒ Object
958 959 960 |
# File 'lib/narray_miss.rb', line 958 def im NArrayMiss.to_nam_no_dup(@array.im,@mask) end |
#imag ⇒ Object
945 946 947 |
# File 'lib/narray_miss.rb', line 945 def imag NArrayMiss.to_nam_no_dup(@array.imag,@mask) end |
#imag=(arg) ⇒ Object
954 955 956 957 |
# File 'lib/narray_miss.rb', line 954 def imag=(arg) @array.image=(arg) self end |
#inspect ⇒ Object
1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 |
# File 'lib/narray_miss.rb', line 1181 def inspect # "array -> " + @array.inspect + "\nmask -> " + @mask.inspect count_line = 0 max_line = 10 max_col = 80 sep = ", " const = Hash.new NArray.constants.each{|c| const[NArray.const_get(c)] = c} str_ret = "NArrayMiss."+const[typecode].downcase+"("+shape.join(",")+"):" if rank == 0 then str_ret += " []" return str_ret else str_ret += "\n" end str = "" index = Array.new(rank,0) index[0] = true i = 1 (rank-1).times{ str_ret += "[ " } while(true) i.times{ str_ret += "[ " } str = @array[*index].inspect ary = str[str.index("[")+1..str.index("]")-1].strip.split(/\s*,\s*/) miss = @mask[*index].where2[1] miss = miss[miss<ary.length].to_a if ary[-1]=="..." && miss[-1]==ary.length-1 then miss.pop end for j in miss ary[j] = "-" end while ( rank*4+ary.join(", ").length > max_col ) ary.pop ary[-1] = "..." end str_ret += ary.join(", ") i = 1 while (i<rank) if index[i]<shape[i]-1 then str_ret += " ]"+sep+"\n" count_line += 1 index[i] += 1 break else str_ret += " ]" index[i] = 0 i += 1 end end if i>=rank then str_ret += " ]" return str_ret elsif count_line>=max_line then str_ret += " ..." return str_ret end (rank-i).times{ print(" ") } end return str_ret end |
#integer? ⇒ Boolean
Others
— NArrayMiss#integer?
return true if (({NArrayMiss})) is byte, sint or int, else false.
— NArrayMiss#complex?
return true if (({NArrayMiss})) is scomplex or complex, else false.
— NArrayMiss#dup — NArrayMiss#coerce(object) — NArrayMiss#inspect
go back to ((<Index>))
1150 1151 1152 |
# File 'lib/narray_miss.rb', line 1150 def integer? @array.integer? end |
#mask(arg) ⇒ Object
904 905 906 907 908 909 910 |
# File 'lib/narray_miss.rb', line 904 def mask(arg) obj = self.dup if arg.class==NArrayMiss then arg = arg.get_array!&arg.get_mask! end obj.set_mask(@mask&arg) end |
#mean(*arg) ⇒ Object
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 |
# File 'lib/narray_miss.rb', line 570 def mean(*arg) if @mask.count_true == 0 then return nil end min_count = 1 =["min_count"] if arg.length!=0 && arg[-1].class==Hash then option = arg[-1] arg2=arg[0..-2] option.each_key{|key| if !.index(key) then raise(ArgumentError,key+" option is not exist") end } min_count = option["min_count"] else arg2=arg end count = @mask.to_type(NArray::INT).sum(*arg2) if count.class == NArray then count = NArrayMiss.to_nam(count,count.ge(min_count)) if count.ge(min_count).count_true == 0 return nil else return self.sum(*arg2)/count end else if count < min_count then return nil else return self.sum(*arg2)/count end end end |
#median(*arg) ⇒ Object
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 |
# File 'lib/narray_miss.rb', line 645 def median(*arg) if arg.length==0 then return @array[@mask].median else nshape = NArray.to_na(@array.shape) nshape[arg]=1 nslice = nshape[nshape.ne(1).where] index = NArray.object(@mask.rank) index[nshape.eq(1).where] = true obj = NArrayMiss.new(@array.typecode,*nslice.to_a) total = 1 nslice.each{|n| total *= n} for i in 0...total index[nshape.ne(1).where] = pos(i,nslice) mask = NArray.byte(*@array.shape).fill(0) mask[*index] = 1 mask = @mask&mask if mask.count_true != 0 then obj[*pos(i,nslice)] = @array[mask].median end end return obj end end |
#mul_add(*arg) ⇒ Object
403 404 405 406 407 408 409 |
# File 'lib/narray_miss.rb', line 403 def mul_add(*arg) if arg.length==1 then return (self*arg[0]).sum else return (self*arg[0]).sum(*arg[1..-1]) end end |
#newdim(*arg) ⇒ Object Also known as: rewrank
762 763 764 765 |
# File 'lib/narray_miss.rb', line 762 def newdim(*arg) obj = self.dup obj.newdim!(*arg) end |
#newdim!(*arg) ⇒ Object Also known as: rewrank!, rewrank=
755 756 757 758 759 |
# File 'lib/narray_miss.rb', line 755 def newdim!(*arg) @array = @array.newdim!(*arg) @mask = @mask.newdim!(*arg) self end |
#none? ⇒ Boolean
918 919 920 |
# File 'lib/narray_miss.rb', line 918 def none? @array[@mask].none? end |
#none_valid? ⇒ Boolean Also known as: all_invalid?
1112 1113 1114 |
# File 'lib/narray_miss.rb', line 1112 def none_valid? @mask.none? end |
#not ⇒ Object
482 483 484 |
# File 'lib/narray_miss.rb', line 482 def not NArrayMiss.to_nam_no_dup(@array.not, @mask.dup) end |
#randomn ⇒ Object
342 343 344 345 346 |
# File 'lib/narray_miss.rb', line 342 def randomn obj = self.dup obj[@mask] = @array[@mask].randomn obj end |
#rank ⇒ Object
225 226 227 |
# File 'lib/narray_miss.rb', line 225 def rank @array.rank end |
#rank_total(*arg) ⇒ Object
237 238 239 |
# File 'lib/narray_miss.rb', line 237 def rank_total(*arg) @array.rank_total(*arg) end |
#real ⇒ Object
Complex compound number (only for scomplex and complex)
— NArrayMiss#real — NArrayMiss#imag — NArrayMiss#conj — NArrayMiss#angle — NArrayMiss#imag=(other) — NArrayMiss#im
942 943 944 |
# File 'lib/narray_miss.rb', line 942 def real NArrayMiss.to_nam_no_dup(@array.real,@mask) end |
#reshape(*arg) ⇒ Object
750 751 752 753 |
# File 'lib/narray_miss.rb', line 750 def reshape(*arg) obj = self.dup obj.reshape!(*arg) end |
#reshape!(*arg) ⇒ Object Also known as: shape=
Changing Shapes of indices
— NArrayMiss#reshape!(size, …)
change shape of array.
— NArrayMiss#reshape(size, …)
same as (({NArrayMiss#reshape!})) but create new object.
— NArrayMiss#shape=(size, …)
same as (({NArrayMiss#reshape!})).
— NArrayMiss#newdim!(dim)
insert new dimension with size=1
— NArrayMiss#newdim(dim)
same as (({NArrayMiss#newdim!})) but create new object.
— NArrayMiss#rewrank!(dim)
same as (({NArrayMiss#newdim!})).
— NArrayMiss#rewrank=(dim)
same as (({NArrayMiss#newdim!})).
745 746 747 748 749 |
# File 'lib/narray_miss.rb', line 745 def reshape!(*arg) @array = @array.reshape!(*arg) @mask = @mask.reshape!(*arg) self end |
#set_invalid(*pos) ⇒ Object Also known as: invalidation
1041 1042 1043 |
# File 'lib/narray_miss.rb', line 1041 def set_invalid(*pos) @mask[*pos] = 0 end |
#set_mask(mask) ⇒ Object
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 |
# File 'lib/narray_miss.rb', line 1053 def set_mask(mask) if mask.class == Array then tmp = NArray.byte(*@mask.shape) tmp[true] = mask mask = tmp end if mask.class == NArrayMiss then mask = mask.to_na(0) end if mask.class == NArray then if mask.typecode != BYTE then raise("mask must be NArrayMiss.byte, NArray.byte or Array") end if @array.shape != mask.shape then raise("mask.shape must be same as array") end @mask = mask.dup return self else raise("mask must be NArray.byte or Array") end end |
#set_missing_value(val) ⇒ Object
1080 1081 1082 1083 |
# File 'lib/narray_miss.rb', line 1080 def set_missing_value(val) obj = self.dup obj.set_missing_value!(val) end |
#set_missing_value!(val) ⇒ Object
1076 1077 1078 1079 |
# File 'lib/narray_miss.rb', line 1076 def set_missing_value!(val) @array[@mask.not] = val self end |
#set_valid(*pos) ⇒ Object Also known as: validation
Mask and missing value
— NArrayMiss#set_valid(index)
validate element at ((|index|)).
((|index|)) must be (({Integer, Range, Array, or ture})).
— NArrayMiss#validation(index)
alias to set_valid
— NArrayMiss#set_invalid(index)
invaliadate element at ((|index|)).
((|index|)) must be (({Integer, Range, Array, or ture})).
— NArrayMiss#invalidation(index)
alias to set_invalid
— NArrayMiss#all_valid
set all elements valid
— NArrayMiss#all_invalid
set all elements invalid
— NArrayMiss#set_mask(mask)
masking by ((|mask|))
— NArrayMiss#set_missing_value(value)
replace invalid elements by ((|value|)).
— NArrayMiss#get_mask!
return (({NArray})) of byte as mask.
— NArrayMiss#get_mask
return (({NArray})) of byte as mask.
— NArrayMiss#get_array!
return (({NArray})) as data.
— NArrayMiss#get_array
return (({NArray})) as data.
— NArrayMiss#valid?
return (({Array})) whose elements are true or false corresponding to valid or invalid of elements, respectively.
— NArrayMiss#all_valid?
return true if all elements are valid, else false.
— NArrayMiss#none_valid?
return true if all elements are invalid, else false.
— NArrayMiss#all_invalid?
alias to none_valid?
— NArrayMiss#any_valid?
return true if any elements are valid, else false.
— NArrayMiss#count_valid
return the number of valid elements.
— NArrayMiss#count_invalid
return the number of invalid elements.
1037 1038 1039 |
# File 'lib/narray_miss.rb', line 1037 def set_valid(*pos) @mask[*pos] = 1 end |
#set_without_validation(*arg) ⇒ Object
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/narray_miss.rb', line 274 def set_without_validation(*arg) if arg.length==1 then if !arg[0] then @mask[] = 0 elsif arg[0].class == NArrayMiss then @array[] = arg[0].get_array! @mask[] = arg[0].get_mask! else @array[] = arg[0] end else if !arg[-1] then @mask[*arg[0..-2]] = 0 elsif arg[-1].class == NArrayMiss then @array[*arg[0..-2]] = arg[-1].get_array! @mask[*arg[0..-2]] = arg[-1].get_mask! else @array[*arg[0..-2]] = arg[-1] end end return self end |
#shape ⇒ Object
228 229 230 |
# File 'lib/narray_miss.rb', line 228 def shape @array.shape end |
#size ⇒ Object Also known as: total, length
231 232 233 |
# File 'lib/narray_miss.rb', line 231 def size @array.size end |
#slice(*arg) ⇒ Object
270 271 272 |
# File 'lib/narray_miss.rb', line 270 def slice(*arg) NArrayMiss.to_nam_no_dup(@array.slice(*arg),@mask.slice(*arg)) end |
#stddev(*arg) ⇒ Object
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 |
# File 'lib/narray_miss.rb', line 604 def stddev(*arg) if @mask.count_true == 0 then return nil end min_count=2 =["min_count"] if arg.length!=0 && arg[-1].class==Hash then option = arg[-1] arg = arg[0..-2] option.each_key{|key| if !.index(key) then raise(ArgumentError,key+" option is not exist") end } min_count = option["min_count"].to_i if min_count<2 raise(ArgumentError, "min_count must be >= 2") end end count = @mask.to_type(NArray::INT).sum(*arg) count2 = @mask.to_type(NArray::INT).accum(*arg) if count.class==NArray then count = NArrayMiss.to_nam_no_dup(count,count.ge(min_count)) if count.get_mask!.count_true == 0 return nil end else if count < min_count then return nil end end if self.integer? then a = self.to_f else a = self end var = ( (a-a.accum(*arg)/count2)**2 ).sum(*arg)/(count-1) obj = NMMath::sqrt(var) return obj end |
#swap_byte ⇒ Object
Byte swap
— NArrayMiss#swap_byte
swap byte order.
— NArrayMiss#hton
convert to network byte order.
— NArrayMiss#ntoh
convert from network byte order.
— NArrayMiss#htov
convert to VAX byte order.
— NArrayMiss#vtoh
convert from VAX byte order.
977 978 979 980 981 |
# File 'lib/narray_miss.rb', line 977 def swap_byte obj = self.dup obj.set_without_validation(@array.swap_byte) obj end |
#to_a ⇒ Object
807 808 809 |
# File 'lib/narray_miss.rb', line 807 def to_a @array.to_a end |
#to_na(*arg) ⇒ Object
820 821 822 |
# File 'lib/narray_miss.rb', line 820 def to_na(*arg) return self.dup.to_na!(*arg) end |
#to_na!(*arg) ⇒ Object
810 811 812 813 814 815 816 817 818 819 |
# File 'lib/narray_miss.rb', line 810 def to_na!(*arg) if arg.length==0 return @array elsif arg.length==1 then self.set_missing_value!(arg[0]) return @array else raise(ArgumentError, "Usage: NArray#to_na([missing_value])") end end |
#to_s ⇒ Object
823 824 825 |
# File 'lib/narray_miss.rb', line 823 def to_s @array.to_s end |
#to_string ⇒ Object
826 827 828 829 830 831 |
# File 'lib/narray_miss.rb', line 826 def to_string obj = NArrayMiss.obj(*@array.shape) obj.set_without_validation( @array.to_string ) obh.set_mask(@mask) obj end |
#to_type(typecode) ⇒ Object
804 805 806 |
# File 'lib/narray_miss.rb', line 804 def to_type(typecode) NArrayMiss.to_nam_no_dup(@array.to_type(typecode), @mask.dup) end |
#transpose(*arg) ⇒ Object
Transpose
— NArrayMiss#transpose(dim0, dim1, …)
transpose array. The 0-th dimension goes to the ((|dim0|))-th dimension of new array.
717 718 719 720 721 722 723 724 |
# File 'lib/narray_miss.rb', line 717 def transpose(*arg) obj = self.dup shape = arg.collect{|i| obj.shape[i]} obj.reshape!(*shape) obj.set_without_validation( @array.transpose(*arg) ) obj.set_mask(@mask.transpose(*arg)) obj end |
#typecode ⇒ Object
241 242 243 |
# File 'lib/narray_miss.rb', line 241 def typecode @array.typecode end |
#valid? ⇒ Boolean
1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 |
# File 'lib/narray_miss.rb', line 1098 def valid? where = self.get_mask!.where2 tf = Array.new(self.total) for i in where[0] tf[i] = true end for i in where[1] tf[i] = false end tf end |
#where ⇒ Object
922 923 924 |
# File 'lib/narray_miss.rb', line 922 def where (@array&@mask).where end |
#where2 ⇒ Object
925 926 927 |
# File 'lib/narray_miss.rb', line 925 def where2 self.where-@mask.where end |
#~@ ⇒ Object
Bitwise operator (only for byte, sint and int)
— NArrayMiss#~@ — NArrayMiss#&(other) — NArrayMiss#|(other) — NArrayMiss#^(other)
420 421 422 |
# File 'lib/narray_miss.rb', line 420 def ~@ NArrayMiss.to_nam_to_dup(~@array, @mask.dup) end |