Hi Communities
I am trying to create a large size of sparsearray as following
base = Permutations[{1, 1, 1, 1, 1, 0, 0, 0, 0, 0}];
dim = Length[base]
AbsoluteTiming[
test = SparseArray[{i_,
j_} /; (Total@Abs[base[[i]] - base[[j]]] == 0 ||
Total@Abs[base[[i]] - base[[j]]] == 2 ||
Total@Abs[base[[i]] - base[[j]]] == 4) -> 1, dim {1, 1}]]
The ideal of above code is that only the element at diagonal of the matrix and only two and four element differ between two bases have the value of 1.
The above code took only ~0.6 second to complete.
However, if I change the base
to following:
base = Select[
Permutations[{1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 0}],
5 <= Total@#[[1 ;; 10]] <= 7 && 5 <= Total@#[[11 ;; 15]] <= 5 &]
It ran out all of my computer's memory (~6GB) and makes the such computation being impossible.
The length of this new base is only 34122. It is not very large. So did I make any thing wrong?
Are there any solutions to this ?
Thank you for reading this.