Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12231

Algorithm for transformation of an 1-D-gradient into a special form of a 2-D-gradient

$
0
0

Assuming there is a 1-D array/list which defines a color gradient I would like to use it in order to create a 2-D color gradient as follows:

Let's for simplicity replace color information with a single numerical value for an example of a 1-D array/list:

[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ]

To keep the gradient progressing diagonally with progress of the largest next value diagonally over the entire array I would like to transform the 1-D sequence into a 2D-array with deliberately chosen shape (i.e. width/height, i.e. number of rows x number of columns where row * columns == length of the 1-D gradient array) as follows:

[[  1  2  4 ] [  3  6  7 ] [  5  9 10 ] [  8 12 13 ] [ 11 14 15 ]]

or

[[  1  2  4  7 10 ] [  3  6  9 12 13 ] [  5  8 11 14 15 ]]

or starting from a sequence:

[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]

to

[[  1  2  4  7 ] [  3  6  9 11 ] [  5 10 13 14 ] [  8 12 15 16 ]]

Is there a ready-to-use out of the box Python module or C-library capable to perform such reshaping of an array or need this special case be coded by hand? And if coding the loops by hand is necessary, what would be the most efficient way of doing this as the sequence I would like to transform is 256³ large in size? I there maybe already ready for use code for such reshaping/transformation out there in the deep space of the Internet I have failed to find asking both the search engines and the LLMs?


Viewing all articles
Browse latest Browse all 12231

Trending Articles