python - Creating new numpy array from existing array efficiently -
I have an existing NMP array (UIT8) that looks like this:
(Value 8-bit, I only include the last 3)
[[00000AAA, 00000BBB, 00000CCC], [00000FFF, 00000EEE, 00000DDD], [00000GGG, 00000HHH, 00000III], [00000LLL, 00000KKK, interested in 00000JJJ]]
and finally I want the data in this form:
[01AAABBB, 01CCCDDD 01EEEFFF, 01GGGHHH, 01IIIJJJ, 01KKKLLL ]
In addition, every second line is reversed.
Currently, I have a long and curved code that can be found in the original list row-per-line and cell-by-cell
Itemprop =" text ">
Here trustees have an approach using built-in commands and vector-style indexing, so it should be very compact (and fast) ):
updated with comment with suggestions
every other row unsnaked_array = NP# Reverse direction. Array (inp_array) unsnaked_array [1 :: 2] = inp_array [1 :: 2, :: - 1] # change a long array unsnaked_array = unsnaked_array.ravel () unsnaked_array & amp; = 0x7 # extra security :) # yoga bits required for every pair of elements (rolled with the first element) and add result_array = (unsnaked_array [:: 2] to & lt; & lt; 3) + unsnaked_array [1 :: 2] + (1 & Lt; <6)
Comments
Post a Comment