Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

two things array/ruby related

For general discussion related FlowStone

two things array/ruby related

Postby tester » Thu Oct 31, 2013 10:19 am

Somewhat I'm overwhelmed, so sorry if some question repeats.

I'm looking for simple (starting to like these single-line codes) ruby solutions to two things.

1. Get column.

Let say that you have an array (x rows, y columns). I'd like to get specific y column, according to separator. Like this.

a/b/c
1/2/3
q/1/m

column 2:

b
2
1

I know there were SM modules for that, but they are appropriately slower than ruby.
Actually it could be like "get multiple columns", similar to what is in p2 in regards to rows.

2. Get multiple rows according to index list.

Let say that I have one array with multiple rows, and second array with list of indexes. On output I'd like to have only these rows, which are indexed in second array. Like this.

array1:
line1
line2
line3
line4
line5

array2:
0
2

output:
line1
line3

---------
I need to redesign some parts of current project, due to green based slowdowns.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: two things array/ruby related

Postby Nubeat7 » Thu Oct 31, 2013 2:34 pm

dont know exactly how you need it but with array.indexes(idx1,idx2,idx3,...) you could call specific indexes from an array..

depending on your needs i would also have a look at hashtables.. in ruby
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: two things array/ruby related

Postby tester » Thu Oct 31, 2013 3:34 pm

It is totally non-audio.

In typical scenario, it's related to external custom lists (text files), made user friendly. Like this:

item1a/item1b/item1c/item1d
item2a/item2b/item2c/item2d
item3a/item3b/item3c/item3d
...
itemNa/itemNb/itemNc/...

where "item" is a whatever word or whatever number; in general, these can be labels associated with other labels or with numerical values, and pretty often - used with randomized selection. Custom lists don't have any headers, they are just lists of items.

(I'm not using comma, because it is interpreted by some FS string prims as well with end line marks).

One thing I'm using pretty often, is - getting specific column of items. In simple short lists, old SM solution works fine (as far I remember, it was named "stride"), but here - I need to speed up the process, thus - using ruby.

Another thing I'm starting to use, is to get selected multiple rows (just by following list of indexes), for example row1 and row3 from the list. Thus - only these items are then in use.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: two things array/ruby related

Postby CoreStylerz » Thu Oct 31, 2013 4:46 pm

Explain better what u need.
Need my support for app development, website or custom scripts?
PM me if you are interested.
Experienced Java, J2EE, PHP, Javascript, Angular, Cloud Solutions developer.
User avatar
CoreStylerz
 
Posts: 327
Joined: Sun Jan 22, 2012 2:19 am
Location: italy

Re: two things array/ruby related

Postby tester » Thu Oct 31, 2013 5:29 pm

There is no way to explain it simpler. :lol:
I need exactly that. In simplest form of ruby.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: two things array/ruby related

Postby Nubeat7 » Thu Oct 31, 2013 6:31 pm

maybe some .join and .select combinations to create an array or more arrays form the string and then select the item per index ( i`m not at home to build something for you ) but why not using 3 arrays instead? also a user input format like this as text file will have a big chance of user input errors which you should take care of... i still would recommend hashtables with some secure input mask to prevent userinput errors..
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: two things array/ruby related

Postby tester » Thu Oct 31, 2013 7:36 pm

What I pointed in above posts - were only examples on the topics itself. It's not that "there are only 3 columns", or that these items have fixed lenghts. It's the idea. The items as strings - are multi-word texts combined numbers (depending on where such solutions are used). Most data is reloaded from external text files, freely edited (and sorted) by user; that why I don't want to add any headers.

These things are relatively easy to get with green prims, but greenery gets slow, when dealing with dozens of iterations at each click. Difference between ruby and greenery is like between fraction of second and few seconds, so it is an issue.

As I said - this is not audio related. It's processing of textual data in various, multiple ways, and dealing with internally associated, numerical data.

I suspect, that first thing (getting the individual column) could be done by using "rotate array" (rotation according to user separator, like "/" - still not sure to make it). Thus - each column would become a row, and rows are indexed automatically in FS by "new line" separator.

As for second part (getting multiple lines according to list of indexes) - I suspect, that there is very easy way to get on output only these lines, that match the indexes on the second list. I just have no idea how to make it.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: two things array/ruby related

Postby trogluddite » Thu Oct 31, 2013 9:00 pm

To use a second array to look up a list of indexes, you can use a special form of "values_at"...
Code: Select all
array1 = ['a', 'b', 'c' ,'d', 'e', 'f']
array2 = [1,3,4]
result = array1.values_at(*array2)   #=> ['b', 'd', 'e']

The * in front of array2 is important - you would normally give 'values_at' a list of indexes as the arguments, e.g. array1.values_at(1,3,4), so an array normally wouldn't work as it isn't an Integer. The * is a special Ruby syntax that 'flattens' an array into a list, so that it gets seen as a sequence of individual parameter values.
(NB - not just for 'values_at', it can be used in other situations like this).

tester wrote:I suspect, that first thing (getting the individual column) could be done by using "rotate array"

You're on the right track - but you need an array where each row is itself an array - i.e. nested array structure. So the string for each row will need converting to array form...
Code: Select all
my_array = ["1/2/3", "a/b/c", "X/Y/Z"]

# Convert rows into sub-arrays
nested_array = my_array.map do |row|
  row.split('/')
end

# You now have a nested array...
# [ ["1","2","3"], ["a","b","c"], ["X","Y","Z"] ]

# Now transpose so that columns become rows and vice versa
transposed_array = nested_array.transpose

# transposed array will now be
# [ ["1","a","X"], ["2","b","Y"], ["3","c","Z"] ]

# Get a column
column = transposed_array[0]  #=> ["1", "a", "X"}
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: two things array/ruby related

Postby Nubeat7 » Thu Oct 31, 2013 9:20 pm

Nubeat7 wrote:dont know exactly how you need it but with array.indexes(idx1,idx2,idx3,...) you could call specific indexes from an array..

depending on your needs i would also have a look at hashtables.. in ruby


my suggestion of using .indexes is a little out of date :lol: it is called .values_at , thanks trog, just had a quick search on google - always better to watch at the actual api doc before posting some outdated stuff without testing

and wow i like this asterisk more in ruby than in c++
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: two things array/ruby related

Postby RJHollins » Thu Oct 31, 2013 9:23 pm

not to distract from the OP ... and thanks for the examples TROG ...

but I've been trying to figure out how to change the output of the RUBY box from the proper ARRAY display:
["1", "a", "X"]


to one that is 'clean' .... 1 a X

or

1
a
X

I'm thinking the array is extracted into a string format. But I more familliar using PRIMS and still easily confused with RUBY. [need more practise :lol: ]

Thanks for info!
RJHollins
 
Posts: 1568
Joined: Thu Mar 08, 2012 7:58 pm

Next

Return to General

Who is online

Users browsing this forum: No registered users and 11 guests