[Solved] Creating many state vectors and saving them in a file


Is this what you’re looking for?

In [2]: num_rows = 10  # should be divisible by 2

In [3]: np.repeat(np.eye(num_rows // 2), 2, axis=0)
Out[3]:
array([[1., 0., 0., 0., 0.],
       [1., 0., 0., 0., 0.],
       [0., 1., 0., 0., 0.],
       [0., 1., 0., 0., 0.],
       [0., 0., 1., 0., 0.],
       [0., 0., 1., 0., 0.],
       [0., 0., 0., 1., 0.],
       [0., 0., 0., 1., 0.],
       [0., 0., 0., 0., 1.],
       [0., 0., 0., 0., 1.]])

In terms of storage in a file, you can use np.save and np.load.

Note that the default data type for np.eye will be float64. If you expect your values to be small when you begin integrating or whatever you’re planning on doing with your state vectors, I’d recommend setting the data type appropriately (like np.uint8 for positive integers < 256 for example).

0

solved Creating many state vectors and saving them in a file