3
$\begingroup$

I have a set of sets:

{{1}, {0}, {1, 1}, {0}, {1, 0, 1}, {0}, {1, 1, 1, 1}, {0}, {1, 0, 0, 0, 1}}

I’m seeking to apply a color rule to only every other set, starting from the first (from left to right), and we need to consider each to have an order starting from and including 2 in ascending magnitude by increments of 1. All disregarded sets are always {0}. So for the set of sets above, their modified order is (excluding those I am denoting with null set):

2, ø, 3, ø, 4, ø, 5, ø, 6

For all sets whose order by this scheme is a prime value, I want all 1’s in their respective set to be colored (custom, not black or white). This means there are 3 colors. The default for ArrayPlot is black and white already - white is 0 and black is 1. Now we are saying that only for the appropriate sets above (with modified order being prime), the 1’s of each such set will be specially colored in the array plot, let's say green.

Kuba helped me earlier but I neglected to specify the extra conditions of skipping sets and applying the coloring to only the 1’s in each set, not all elements therein.

If it’s done right the rows corresponding to the {0} sets should remain white, as should any 0’s in even sets we consider belonging to a prime modified order, and non-prime ordered sets regardless, but nonprime modified ordered sets give black for 1’s, while colored for their prime counterparts, all with the same color. Since for our example again the modified order…

For… {{1}, {0}, {1, 1}, {0}, {1, 0, 1}, {0}, {1, 1, 1, 1}, {0}, {1, 0, 0, 0, 1}}

Is… 2, ø, 3, ø, 4, ø, 5, ø, 6

1’s are colored in set order 2, 3, and 5 only, but black in sets 4 and 6. only white is showed for any sets of ø (null) order, and all 0’s regardless of set belonged to.

$\endgroup$
1
$\begingroup$

Perhaps something like:

lst = {{1}, {0}, {1, 1}, {0}, {1, 0, 1}, {0}, {1, 1, 1, 1}, {0}, {1, 0, 0, 0, 1}};
t = Riffle[1 + Boole /@ PrimeQ /@ Range[2, 1 + Ceiling[Length[lst]/2]], 
           0, If[OddQ @ Length@ lst, 2, {2, -1, 2}]];
lst2 = t lst;

Row[ArrayPlot[#, ColorRules -> {2->Red, 1->Black}, ImageSize -> 200]& /@ {lst, lst2}, Spacer[5]]

enter image description here

Or, define a function that does the required transformation:

tF = #  Riffle[1 + Boole /@ PrimeQ /@ Range[2, 1 + Ceiling[Length[#]/2]], 0, 
               If[OddQ@Length@#, 2, {2, -1, 2}]] &;

lstb = {{1}, {0}, {1, 1}, {0}, {1, 0, 1, 0, 0, 1}, {0}, {1, 1, 1,  1}, {0}, {1, 0, 0, 0, 1}, {0}};
ArrayPlot[tF@lstb, ColorRules -> {2 -> Red, 1 -> Black}, ImageSize -> 200]

enter image description here

$\endgroup$
1
$\begingroup$
data = {{1}, {0}, {1, 1}, {0}, {1, 0, 1}, {0}, {1, 1, 1, 1}, {0}, {1, 0, 0, 0, 1}};

ArrayPlot @ Module[{i = 2}, If[# =!= {0} && PrimeQ[i++], Red #, #] & /@ data]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.