Here is the problem:
I have 3 states (vectors in 3D), that I would like to pair up (e.g. (a,a), (a,b), (a,c), (b,a), (b,b), ...) into elements of a 3X3 matrix.
In a more abstract way, I have a set of 3 arrays with 3 entries, and I would like to produce a 3x3 array where the entries themselves are an array of 2 of the original arrays. (A lot of nesting).
For the 3 cartesian basis vectors this would look like: a = (1,0,0), b = (0,1,0), c = (0,0,1)
and the matrix would be:
M = | {(1,0,0),(1,0,0)} {(1,0,0),(0,1,0)} {(1,0,0),(0,0,1)} |
| {(0,1,0),(1,0,0)} {(0,1,0),(0,1,0)} {(0,1,0),(0,0,1)} |
| {(0,0,1),(1,0,0)} {(0,0,1),(0,1,0)} {(0,0,1),(0,0,1)} |
# I appreciate I have formatted the matrix in code rather than LaTeX
# but I can't find the functionality to do this on StackOverflow
so the matrix has elements that are arrays of 2 entries, and the entries of those arrays are my 3D vectors (arrays with 3 entries).
The code that I am using to try to implement this is:
import numpy as np
a= np.array([0,0,0])
b= np.array([0,0,1])
c= np.array([0,2,0])
states = np.array([a,b,c])
def cycler(states):
matrix = np.zeros((3,3))
for x in range(0,3):
for y in range(0,3):
matrix[x,y]= np.array([states[x],states[y] ])
return matrix
cycler(states)
However, when I run this code, I am getting an error on the line:
matrix[x,y]= np.array([states[x],states[y] ])
with the error message:
ValueError: setting an array element with a sequence.
As a bit of python newbie I'd really appreciate a bit of help to allow me to create the matrix of pairs of vectors! (For context, my state vectors a, b, c are not the basis vectors, and I will then later be writing a function that will read the elements of the matrix, using the array of the 2 3D states in a further calculation.)