Randomly assigning labels to elements in a 2 dimensional array in Python -


let's have 4x4 symmetrical 2 dimensional array 0's on long diagonal this:

[0 1 2 3] [1 0 3 4] [2 3 0 5] [3 4 5 0] 

i want randomly equally assign 2 labels every column, in order categorize these numbers groups. example, group 1 might contain numbers columns 1 , 3, , group 2 might contain rest of columns 2 , 4.

using python, how randomly equally (so there equal amount of every label) assign n labels columns in mxm 2 dimensional symmetrical array?

i'm not sure concept of labelling columns works here. these not columns elements same index point in multiple lists. why not create labellist , use access 'columns' want. can randomly order labellist

import random labellist = [1, 2, 3, 4] random.shuffle(labellist) print labellist 

now have randomly ordered label list, , can use in order access '4x4 array' list of 4 lists in python terms. in each list within array 'column1' accessed referencing labellist[0] , on. if want work in terms of pairs of columns first 2 elements of labellist refrence index points in lists interested in pairing.

for example:

list = [[0, 1, 2, 3],[1, 0, 3, 4],[2, 3, 0, 5],[3, 4, 5, 0]] elem in list:      print list[labellist[0]] 

will return 'column' referenced first element in labellist has been randomly shuffled point.

i'm not sure looking for, hope helps.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -