Questions tagged [narray]

NArray is an Numerical N-dimensional Array class for Ruby.

NArray is an Numerical N-dimensional Array class. Supported element types are 1/2/4-byte Integer, single/double-precision Real/Complex, and Ruby Object. This extension library incorporates fast calculation and easy manipulation of large numerical arrays into the Ruby language. NArray has features similar to NumPy, but NArray has vector and matrix subclasses.

22 questions
7
votes
3 answers

What are the advantages of using Ruby NArray over Array?

I just came across the NArray library for Ruby -- please excuse my ignorance when asking this question :) What are the advantages of using the NArray library over the standard Ruby Array implementation? I've seen that NArray is geared towards…
Tilo
  • 33,354
  • 5
  • 79
  • 106
5
votes
1 answer

Selecting values below a threshold and anchored at the left or right using Ruby NArray

Using NArray, is there some nifty way to create masks of arrays with values below e.g. 5, but only for runs of values anchored a the left or right side, E.g. this 1-D array: [3, 4, 5, 7, 1, 7, 8] would result in: [1, 1, 0, 0, 0, 0, 0] And this 2-D…
maasha
  • 1,926
  • 3
  • 25
  • 45
2
votes
2 answers

Replacing values in a byte type NArray in Ruby

I am looking for a way to replace all occurrences of 'A' with 1, 'T' with 2, 'C' with 8, and 'G' with 16 in a byte array. How can this be done?
maasha
  • 1,926
  • 3
  • 25
  • 45
2
votes
0 answers

Is it possible to use Ruby FFI to send a Ruby (C API) VALUE to a function?

I'm currently trying to bridge Numo::NArray and FFI, so that an FFI Pointer can access the raw data in a Numo::NArray without having to copy data through String like I do now (thus causing GC churn and a wasted extra copy). There is a C function…
nitrogen
  • 1,559
  • 1
  • 14
  • 26
2
votes
1 answer

How to access individual elements of a vector element using pointer?

I want to do a pre-order traversal of an n-array tree. My tree node struct contains a vector pointer member. So, how can I iteratively call the members. I want to do something like: for(i in node->children){ cout<
2
votes
1 answer

Ruby's narray gem installation error on Windows

I'm trying to install the NArray gem for Ruby to do some math functions. I'm running Ruby version 2.0.0p353 [x64-mingw32] on Windows with gem 2.014 When I attempt to install the NArray gem, it produces the following error: D:\DocPerso\Workspace…
DBelge
  • 21
  • 2
2
votes
2 answers

Converting NArray to Magick::Image in Ruby

Is there an efficient way to create an RMagick image from the data in a 2D NArray (a Ruby class that's supposed to be more efficient than regular arrays), or are the two libraries just incompatible in their data types? The following code works,…
user2055867
  • 81
  • 1
  • 1
  • 5
2
votes
1 answer

Avoiding iterating over NArray

I have a bunch of points defined as 2x2 NArrays, and I can't seem to figure out how to avoid iterating. Here's what I have that works: # Instantiate an example point point = NArray[[4, 9], [1, 1]] # Create a blank array to fill possible_points =…
acsmith
  • 1,466
  • 11
  • 16
1
vote
4 answers

How to add a row to a two-dimensional Ruby NArray?

I want to add a row to a two-dimensional NArray. The way described in NArray 0-7 Tutorial is pretty complex - and I wonder if there is a more simple way. So if I have two NArrays: n1 = [[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10,…
maasha
  • 1,926
  • 3
  • 25
  • 45
1
vote
1 answer

How to expand/reduce a two-dimensional Ruby NArray?

If I have a Narray with the shape 100, 10000 and want to expand it to say 100, 20000 (basically add rows) what is the proper way to achieve this? To expand massive Narrays I would like to avoid using a temporary Narray for memory reasons.
maasha
  • 1,926
  • 3
  • 25
  • 45
1
vote
1 answer

How to locate intervals of non-empty values in Ruby's NArray?

I am interested in locating all non-empty intervals in a NArray as tuples of [begin, end] type. So if we have a NArray of a given size and all values at index positions 100 ... 200, 300 ... 400, etc are non-zero, I would like to obtain an array like…
maasha
  • 1,926
  • 3
  • 25
  • 45
1
vote
1 answer

Reading files into Ruby Numo::NArray

I have given number of files, which all have the same size. What I'm trying to do is to load those files into Numo::Narray in a way that every file needs to be in a different row of this array. Number of files and their size is known before creating…
railsmk
  • 23
  • 4
1
vote
1 answer

Ruby matrix addition to multi dimensional array

Multidimensional Matrix array is like this arr1 = Matrix[[0.9742006046104146, 0.9164380106962612, 0.39571440216724874], [1.3793903493310324, 1.8988033906016721, 1.2768961254764901], [0.42334074004480604,…
arjun
  • 1,594
  • 16
  • 33
1
vote
1 answer

Ruby NArray.to_na() and Python numpy.array()

Suppose I have the following string. irb(main):074:0> line = "#!/usr/bin/ruby\n#\n# Gen" irb(main):078:0> NArray.to_na(line,Float) => NArray.float(3): [ 9.05457e+164, 3.30198e-258, 6.1531e+223 ] How do I mimic this behavior with Python using…
idealistikz
  • 1,247
  • 5
  • 21
  • 35
1
vote
2 answers

Ruby NArray optimisations for downsample and conditional change

I am creating input to ruby-fann, doing as much manipulation in narray as I can for performance reasons. Typically I am manipulating 2D 200x200 arrays of floats, and need to repeat processing many 1000s of times. Using just NArray, I get acceptable…
Neil Slater
  • 26,512
  • 6
  • 76
  • 94
1
2