Store matrices in dictionary

hey, i was trying to store these feedback matrices in a dictionary with:

matrices.do{|matrix, i|
	~fbMatrixDict.add(i.asSymbol -> matrix);
};

Is there a method for getting the name of the array so it could be used as a key inside the dictionary?
so i could use the dictionary like this: ~fbMatrixDict[\householder];
instead of: ~fbMatrixDict[\0];

Ive looked at the helpfile of Array and couldnt find it.

(
var matrices, householder, puckette, hadamard_4x4, hadamard_8x8, hadamard_16x16;

householder = [
	[ -1.0, 1.0, 1.0, 1.0 ],
	[ 1.0, -1.0, 1.0, 1.0 ],
	[ 1.0, 1.0, -1.0, 1.0 ],
	[ 1.0, 1.0, 1.0, -1.0 ]
]  * 0.5;

puckette = [
	[0, 1, 1, 0],
	[-1, 0, 0, -1],
	[1, 0, 0, -1],
	[0, 1, -1, 0]
]  * sqrt(2).reciprocal;

hadamard_4x4 = [
	[ 1,  1,  1,  1 ],
	[ 1, -1,  1, -1 ],
	[ 1,  1, -1, -1 ],
	[ 1, -1, -1,  1 ],
]  * ( sqrt(2).reciprocal * sqrt(2).reciprocal );

hadamard_8x8 = [
	[ 1,  1,  1,  1,  1,  1,  1,  1 ],
	[ 1, -1,  1, -1,  1, -1,  1, -1 ],
	[ 1,  1, -1, -1,  1,  1, -1, -1 ],
	[ 1, -1, -1,  1,  1, -1, -1,  1 ],
	[ 1,  1,  1,  1, -1, -1, -1, -1 ],
	[ 1, -1,  1, -1, -1,  1, -1,  1 ],
	[ 1,  1, -1, -1, -1, -1,  1,  1 ],
	[ 1, -1, -1,  1, -1,  1,  1, -1 ],
]  * ( sqrt(2).reciprocal * sqrt(2).reciprocal * sqrt(2).reciprocal );

hadamard_16x16 = [
	[ 1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1],
	[ 1,  -1,   1,  -1,   1,  -1,   1,  -1,   1,  -1,   1,  -1,   1,  -1,   1,  -1],
	[ 1,   1,  -1,  -1,   1,   1,  -1,  -1,   1,   1,  -1,  -1,   1,   1,  -1,  -1],
	[ 1,  -1,  -1,   1,   1,  -1,  -1,   1,   1,  -1,  -1,   1,   1,  -1,  -1,   1],
	[ 1,   1,   1,   1,  -1,  -1,  -1,  -1,   1,   1,   1,   1,  -1,  -1,  -1,  -1],
	[ 1,  -1,   1,  -1,  -1,   1,  -1,   1,   1,  -1,   1,  -1,  -1,   1,  -1,   1],
	[ 1,   1,  -1,  -1,  -1,  -1,   1,   1,   1,   1,  -1,  -1,  -1,  -1,   1,   1],
	[ 1,  -1,  -1,   1,  -1,   1,   1,  -1,   1,  -1,  -1,   1,  -1,   1,   1,  -1],
	[ 1,   1,   1,   1,   1,   1,   1,   1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1],
	[ 1,  -1,   1,  -1,   1,  -1,   1,  -1,  -1,   1,  -1,   1,  -1,   1,  -1,   1],
	[ 1,   1,  -1,  -1,   1,   1,  -1,  -1,  -1,  -1,   1,   1,  -1,  -1,   1,   1],
	[ 1,  -1,  -1,   1,   1,  -1,  -1,   1,  -1,   1,   1,  -1,  -1,   1,   1,  -1],
	[ 1,   1,   1,   1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   1,   1,   1,   1],
	[ 1,  -1,   1,  -1,  -1,   1,  -1,   1,  -1,   1,  -1,   1,   1,  -1,   1,  -1],
	[ 1,   1,  -1,  -1,  -1,  -1,   1,   1,  -1,  -1,   1,   1,   1,   1,  -1,  -1],
	[ 1,  -1,  -1,   1,  -1,   1,   1,  -1,  -1,   1,   1,  -1,   1,  -1,  -1,   1],
] * ( sqrt(2).reciprocal * sqrt(2).reciprocal * sqrt(2).reciprocal * sqrt(2).reciprocal );

matrices = [ householder, puckette, hadamard_4x4, hadamard_8x8, hadamard_16x16 ];

~fbMatrixDict = Dictionary.new;

/*
~fbMatrixDict.add(\householder -> householder);
~fbMatrixDict.add(\puckette -> puckette);
~fbMatrixDict.add(\hadamard4x4 -> hadamard_4x4);
~fbMatrixDict.add(\hadamard8x8 -> hadamard_8x8);
~fbMatrixDict.add(\hadamard16x16 -> hadamard_16x16);
*/

matrices.do{|matrix, i|
	~fbMatrixDict.add(i.asSymbol -> matrix);
};
)

~fbMatrixDict[\4];

~fbMatrixDict[\householder];
~fbMatrixDict[\puckette];
~fbMatrixDict[\hadamard4x4];
~fbMatrixDict[\hadamard8x8];
~fbMatrixDict[\hadamard16x16];

~fbMatrixDict.clear;

Arrays don’t have names.

You’re storing them in variables, but the variable name is not a property of the array. So there is no way to ask an array what its name is.

hjh

thank you. is there another good solution?

Why not directly store it in a dictionary?

(
// make a library of matrices
var matlib = ();
matlib[\myspecialmatrix] = [[1, 0], [0,1]];
matlib[\anotherone] =  [ [1,0,0], [0,1,0], [0,0,1]] * sqrt(2).reciprocal;

// use one
matlib[\anotherone].postln;
)

yes of course :slight_smile:
ive been thinking way too complicated.
thanks a lot :slight_smile: