To specify an array of length L in Mathematica, where each entry is someElement, I'm accustomed to writing:
exArray=Array[someElement &, L];
However, let's say that I want to (quickly) generate an array of length L where there are n copies of elementOne and L- n copies of elementTwo. Maybe elementOne is the string character A and elementTwo is the string character B. I'd like to be able to position the two elements in two different ways: (1) where the first n elements are all elementOne and the remaining elements are all elementTwo, and (2) where we have a uniform random sample from the set of all possible arrays where there are n copies of elementOne and L - n copies of elementTwo.
Are there simple "one-liners" to do (1) + (2)?
ConstantArraywithJoinfor (1) andRandomSamplefor (2)? – rm -rf Jan 19 '14 at 20:05Arrayis more flexible, but in this context, what you have andConstantArraygive the same result. You might find the 3rd argument ofConstantArrayuseful if you're initializing sparse arrays. I generally like to write code that "reads well", so if the intent of the line is to generate a constant array, I'll go withConstantArray. – rm -rf Jan 19 '14 at 20:11