I have a row array as shown below:
X1 Y1 Z1 X2 Y2 Z2 X3 Y3 Z3 X4 Y4 Z4 ..... Xn Yn Zn
This row array always starts with the value of X and with the value of Z. I want to rearrange them as a multidimensional array:
X1 X2 X3 X4 X5 .... Xn
Y1 Y2 Y3 Y4 Y5 .... Yn
Z1 Z2 Z3 Z4 Z5 .... Zn
The size of the original array varies in each case. Any help to how to approach this problem would be helpful.
Use reshape function setting second dimension as []
reshaped_array = reshape(myarray,3,[]);
Related
I have one table from this type:
Equipment TimestampEqmt
truck1 timetruck1
truck2 timetruck2
truck3 timetruck3
truck1 timetruck4
truck2 timetruck5
truck3 timetruck6
and another with GPS coordinates for the trucks
Equipment TimestamGPS X Y Z
truck1 TimestamGPS1 X1 Y1 Z1
truck2 TimestamGPS2 X2 Y2 Z2
truck3 TimestamGPS3 X3 Y3 Z3
truck1 TimestamGPS4 X4 Y4 Z4
truck2 TimestamGPS5 X5 Y5 Z5
truck3 TimestamGPS6 X6 Y6 Z6
truck1 TimestamGPS1 X7 Y7 Z7
truck2 TimestamGPS2 X8 Y8 Z8
truck3 TimestamGPS3 X9 Y9 Z9
truck1 TimestamGPS1 X10 Y10 Z10
truck2 TimestamGPS2 X11 Y11 Z11
truck3 TimestamGPS3 X12 Y12 Z12
How to get for every TimestampEqmt and Equipment from first table, first GPS coordinates where TimestamGPS < TimestampEqmt?
The result should be like this:
Equipment TimestampEqmt TimestamGPS X Y Z
truck1 timetruck1 TimestamGPS7 X7 Y7 Z7
truck2 timetruck2 TimestamGPS11 X11 Y11 Z11
truck3 timetruck3 TimestamGPS12 X12 Y12 Z12
Which means that TimestamGPS7 is the first smaller timestamp depending on timetruck1 for truck1.
I am trying to let the program draw a hexagon, The program should let the user enter the coordinates of two points only, I will assume those points are the terminals of a side, then I need to calculate the coordinates of other four points, but how?
P.S: I use the library graphics.h that contains draw polygon which requires 2 arrays of x and y coordinates for all points
Given two points (x1, y1), (x2, y2), the next point on the hexagon can be computed with the formulas
dx = x2 - x1
dy = y2 - y1
x3 = x2 + ((√3)/2) dx - (1/2) dy
y3 = y2 + (1/2) dx + ((√3)/2) dy
These are derived from general rotation formulas; note that cos 60° = (√3)/2 and sin 60° = 1/2.
I was looking for a solution (avoiding vba) to reorganize 3 columns representing data1, data2, and f(data1,data2) into a 2d array.
The data is as follows:
X1 X2 Z_1_2
X1 X3 Z_1_3
X1 X4 Z_1_4
X1 X5 Z_1_5
X2 X3 Z_2_3
X2 X4 Z_2_4
X2 X5 Z_2_5
X3 X4 Z_3_4
X3 X5 Z_3_5
X4 X5 Z_4_5
Edit: I will give some more details...
X are strings and Z are numerics.
The results should be as following:
X1 X2 X3 X4 X5
X1 1 Z_1_2 Z_1_3 Z_1_4 Z_1_5
X2 Z_1_2 1 Z_2_3 Z_2_4 Z_2_5
X3 Z_1_3 Z_2_3 1 Z_3_4 Z_3_5
X4 Z_1_4 Z_2_4 Z_3_4 1 Z_4_5
X5 Z_1_5 Z_2_5 Z_3_5 Z_4_5 1
Thanks !!!
So you need to set up the headers, correctly both the row and column headers.
Then if the Upper left cell put this formula:
=IFERROR(INDEX($C:$C,MATCH($G2&"|"&H$1,$A:$A&"|"&$B:$B,0)),IFERROR(INDEX($C:$C,MATCH(H$1&"|"&$G2,$A:$A&"|"&$B:$B,0)),1))
This is an array formula and needs to be confirmed with Ctrl-Shift-Enter instead of just enter. Copy and fill the rest of the array.
One warning this will take time to compute, It can be sped up by limting the full column references to only those with data; $C:$C in this instance would be $C$1:$C$10.
something like that?
=IF(F$1=$E2,1,INDEX($C$1:$C$10,IFERROR(MATCH(F$1&"_"&$E2,$A$1:$A$10&"_"&$B$1:$B$10,),MATCH($E2&"_"&F$1,$A$1:$A$10&"_"&$B$1:$B$10,))))
This is an array formula and must be confirmed with Ctrl+Shift+Enter.
if you get worried by the & you can avoid it like this:
=IF(F$1=$E2,1,INDEX($C$1:$C$10,MAX(ROW($1:$10)*((F$1=$A$1:$A$10)*($E2=$B$1:$B$10)+($E2=$A$1:$A$10)*(F$1=$B$1:$B$10)))))
This is an array formula and must be confirmed with Ctrl+Shift+Enter.
I have a file which contains:
x1 x2 x3 x4
x5 x6 x7 x8
x9
Which I want:
x1
x2
x3
.
.
How you do that using awk or in another ways?
With awk:
$ awk '1' RS=' ' ORS='\n' file
x1
x2
x3
x4
x5
x6
x7
x8
x9
However personally I would do:
$ xargs -n1 < file
x1
x2
x3
x4
x5
x6
x7
x8
x9
or:
$ grep -o '\S*' file
x1
x2
x3
x4
x5
x6
x7
x8
x9
This is the prototype for the function:
v4si __builtin_ia32_shufps (v4si, v4si, int)
On some websites I found they had but hex in the int field, and it looked liked it separated high and low bits, but what I want is a logical 32 bit shift.
X3 X2 X1 X0 shifted by 32 bits to get X2 X1 X0 0
Another example using 2 v4si vectors:
X7 X6 X5 X4 | X3 X2 X1 X0, where each X is a 32 bit and what I want for a shift is the
same a logical shift, but with each vector element. So:
X7 X6 X5 X4 | X3 X2 X1 X0 << 2 = X5 X4 X3 X2 | X1 X0 0 0
Is shufps the right command to do this?
Looking at your example with two vectors I think what you're probably looking for is _mm_alignr_epi8 (PALIGNR). This works for any shift of a pair of vectors by an arbitrary number of bytes, so you would need to multiply the shift parameter by sizeof(int), e.g.
v = _mm_alignr_epi8(v0, v1, 2 * sizeof(int));
Note that this instruction is only available in SSSE3 and later, which means pretty much any Intel CPU since ~ 2005.