Vector Arguments in Functions Part 2

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...

Vector Arguments in Functions Part 2

Postby REMINGTON30 on Mon Sep 25, 2017 7:33 pm

Consider a user-defined dyadic function Cone5.
Ans←Fstream Cone5 Thetas
Arguments are: Fstream←1.4 2.2 287 300 100 50
and Thetas which is a input angle in radians.

The elements of Fstream are fixed for the remainder of this Forum post.
If run for a single input angle, say, Thetas←0.8,

Ans←Fstream Cone5 0.8

The result Ans is a 50 row, 7 column matrix,i.e., ⍴Ans is 50 7. The individual elements in Ans can be accessed as usual, e.g., Ans[40;5]. The difficulty occurs when the argument Thetas becomes a vector. For example, Thetas←0.8 0.9 1.0. The current method uses the Each Operator:

Ans←Fstream Fstream Fstream Cone5¨ 0.8 0.9 1.0

⍴Ans is now 3 and it appears that the result Ans is now a nested array with Ans[1] being the first 50 row, 7 column matrix; Ans[2] being the second 50 row, 7 column matrix; and, Ans[3] being the third 50 row, 7 column matrix. Numerically, the results are correct. However, I have not been able to access the individual elements in the result. Question 1: How do I access the individual elements in the result? Attempts such as (Ans[1])[40;5] or 40 5⌷Ans[1] do not work. Question 2: How could the result Ans be assigned to a rank 3 array with shape 3 50 7?

Any suggestions would be welcome.
REMINGTON30
 
Posts: 19
Joined: Fri Aug 11, 2017 2:17 pm

Re: Vector Arguments in Functions Part 2

Postby Morten|Dyalog on Mon Sep 25, 2017 11:59 pm

Assuming a default migration level, the mix function (↑) should turn your 3-element vector of 50x7 matrices into a 3-dimensional array of shape (3 50 7).

Your problem with indexing twice is happening because Ans[1] is still enclosed. It remains a scalar and can therefore not be indexed as a matrix. You could use (1⊃Ans) to both select the first item and disclose it, resulting in a matrix which you can index: (1⊃Ans)[40;5].

Alternatively, you can reach two levels into the nested array with a single indexing operation: Ans[⊂1 (40 5)].

Hope this helps!
User avatar
Morten|Dyalog
 
Posts: 394
Joined: Tue Sep 09, 2008 3:52 pm

Re: Vector Arguments in Functions Part 2

Postby REMINGTON30 on Tue Sep 26, 2017 3:51 pm

Morten:

Thank you for the outstanding recommendations. All the methods that you mentioned worked perfectly. The use of disclose ⊃ creates rank 2 arrays that can be transferred to Excel using SaveXL. The use of mix ↑ stores the entire result in a rank 3 array with each element accessible for further analysis.
REMINGTON30
 
Posts: 19
Joined: Fri Aug 11, 2017 2:17 pm


Return to New to Dyalog?

Who is online

Users browsing this forum: No registered users and 1 guest