Feature Request: URScript Matrix Element Indexing Improvement

URScript Example:

a = [[1, 2], [3, 4]]

b = a[0,0]

c = a[0]

the result of b is 1 as expected

the expected result of c is the first vector in a, [1,2], but instead is:

'Index out of range'

Could we access a multidimensional element using one of the following?

c = a[0,]
c = a[0]

What were the results you expected to receive for b and c?

Thanks Matt, just updated the first post. Looking to get the first vector ([1,2]) like you would get the first pose in a list of poses.

What is the language you used for this example? It looks like it is python

The issue I see is with array b not c. to get a specific value in python, you have to declare as b=a[0][0], not as a[0,0].

The array c might be initialized to a size 1 or 0. I would check for an issue on your code because the ‘Index out of range’ is an error message from the python side.

check this example:

Ooh appreciate your response but this in URScript. Believe me I would also like slicing and negative indexing like in python but I’ll settle for the basic features for now haha.

Give it a try using the new matrix/multidimensional array functionality in SW 5.9 and see what you get.

Derp, I completely skipped over the part where you said URScript on the first post. My bad, :smile:.

Hi, I have the same problem of indexing one column/row of a matrix. Did you solve it?

def get_element(mat, i, j):
     temp = mat[i]
     return temp[j]
end

Thus solving the problem forever, issue closed /s

opposite for assignment

Edit: This was wrong, update here:

HI Terry, thank u for the support. I’ve tried to add this script in polyscope, but it failed the execution.
I’ve an error with temp = mat[i] with the following message: the variable Matrix is not indexable!

Ooh, yea you’re going to hate this more but what we actually did is used the tried and tested @mbush technique and used another language to generate this:

def get_element(mat, index, size):
    if size == 1:
        temp = 0
    elif size == 2:
        temp = [0, 0]
    end  # continue this trend
    count  = 0
    while count < size:
        temp[size] = mat[index, size]
        count = count + 1
    end
end

matrix = [[0, 1], [2,3]]
element_size = 2

# Output is [2, 3]
row = get_element(matrix, 1, element_size)

That’s insane. There is no way to index a row/column in 2022. UR must do more on the programming side.
Thank u @terryc for the support!

1 Like

No problem! My favourite URScript feature is using other scripting languages to procedurally generate missing functionality.