Hi,
I have
z: 199 6 # 0;
h: til 199
x: 1 4 3 5 0 4 3 2 2 0 2 2 4 2 2 2 2 1 3 1… (199 values, 0 through 5)
I’ve done the following
hh: h,'x to get
0 0
1 1
2 2
3 1
4 3
5 3
6 3
7 1
8 2
9 3
10 3
11 1
12 1
13 2
14 4
15 2
16 5
17 3
18 1
19 1
20 1
21 1
..
I’d like to set values inside z to 1, based on hh.
for example, take hh[6] -> 6 3 , meaning I want to set zz[6;3]:1
I know I’m close, but missing something important.
please advise,
thanks,
Kumar
Hi
You could use multivalent over to fill in z using the indices of hh:
{[z;hh] z[hh 0;hh 1]:1; z}/[z;hh]
Basically this iterates through each row of hh. updating z at the indices specified.
To get a better idea of how this works you could use scan to see the step-by-step output of the function.
Regards,
Thomas Smyth
AquaQ Analytics
If your z matrix is global you can amend in place
n:10000;
z:(n;n)#0 ;
hh:til[n],'n?n;
q)\ts .[`z;;:;1] each hh
7 131456
Terry
Wow, thanks, guys.I was trying something akin to the ‘enclose’(?) function inside APL. That way, each row of hh could be used as a scalar to index into z. But haven’t had too much luck that either.
Kumar
Attila
March 25, 2016, 8:24am
5
n:10000;
z:(n;n)#0 ;
hh:til[n],'h:n?n;
q)\ts a:z .[;;:;1]/hh
4309 1310982624
as Terry was showing in-place amend is way faster for obvious reasons
q)\ts .'[`z;hh;:;1]
6 262432
q)z~a
1b
if your actual usage also has increasing rows too then you can also do
q)z:(n;n)#0 ;
q)\ts @'[z;h;:;1]
149 1310851376
q)a~@'[z;h;:;1]
1b
Cheers,
Attila
Nope, number of rows are fixed. I’m manipulating a dataset read from disk.
Thanks, Attila.
Kumar