Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

ring Creating a Multi-Dimensional Array using List

###---------------------------------------------------------
### Create Array -- Dimensions Any Size:  3D, 4D, 5D etc

dimList = [4,3,4]
bList   = createDimList(dimList)

###---------------------------------------------------------
### Populate the arrays using a counter 1 ,  4x4x4 = 256 , 2x3x4x5x6 = 720

Counter = 1

for Col=1 to dimList[1]
  for Row=1 to dimList[2]
    for Dep=1 to dimList[3]
            blist[Col][Row][Dep] = Counter
            Counter++
    next
  next
next

###-----------------------------------------------
### Print the array elements in block format

for Col=1 to dimList[1]
  for Row=1 to dimList[2]
    for Dep=1 to dimList[3]
            See bList[Col][Row][Dep] See " "
    next
    See nl
  next
    See nl
next

###===========================
### FUNCTIONS

###-----------------------------------------------------------------------
### Recursive Create a Dimension Array
### Call by passing an array of dimensions: dimList = [2,3,4,5]
### Drop the first entry every iteration call, making newParms
###
### Example:
###    dimList = [4,2,3,2]                <<< Number and size of dimensions in array format
###    bList   = createDimList(dimList)   <<< Call using the array as input

func createDimList(dimArray)

     sizeList = len(dimArray)

     newParms = []
     for i = 2 to sizeList
        Add(newParms, dimArray[i])
     next

     alist = list(dimArray[1])

     if sizeList = 1
        return aList
     ok

     for t in alist
         t = createDimList(newParms)
     next

return alist
Source by ring-lang.github.io #
 
PREVIOUS NEXT
Tagged: #ring #Creating #Array #List
ADD COMMENT
Topic
Name
7+5 =