Trouble creating multi dimensional array. 0 to 26 in 3 dimensions.


Joined
Apr 7, 2022
Messages
9
Reaction score
0
Hi Guys,

Below is some excel VBA code that shows what I am trying to do in Python.

Code:
Sub test()

i = 1
For x = 0 To 26
For y = 0 To 26
For Z = 0 To 26


Cells(i, 1) = x
Cells(i, 2) = y
Cells(i, 3) = Z

i = i + 1
Next Z
Next y
Next x

End Sub

I am trying to make an array in python that gives a 3 dimensional matrix that shows every combination of 1 to 26 in all 3 dimensions.
below is my attempt of the code:
Python:
ColourBlockSize = 10 #(x,x,x) sized blocks to split the 255 R-G-B colours for finding the Mode (most common colour)
NumberofColourBlocks = math.ceil(255/ColourBlockSize) #number of ColourBlocks in one dimension
num01 = int(math.pow(NumberofColourBlocks+1,3))
ColourBlockArray  = np.empty([NumberofColourBlocks+1,NumberofColourBlocks+1,NumberofColourBlocks+1], dtype=np.int)

The resulting array should have an X,Y,Z columns with 19683 rows = (26+1)^3.
My code gives the correct shape array, 3 columns and 19683 rows but the array is full of zeros, the array should look something like the following:

part of array.jpg

Thanks!

Edit/Additional Context:
I am trying to create an array for R,G,B colours (Red, Green, Blue which each vary from 0 to 255). I want to take a photo, and have that photo measure pixel colours by categorizing them into groups/"buckets". whichever "bucket" has the greatest number of occurrences, means the colour is mostly that value, which is a variable for other code.
 
Last edited:
Ad

Advertisements

Joined
May 11, 2022
Messages
58
Reaction score
5
so you don't need a 3d array, only a 2d array with 3 columns.
Code:
color = []
for i in range(0,255):
   for j in range(0,255):
      for k in range(0,255):
         color += [i,j,k]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top