Ask Your Question
1

What is the method for converting a sparse matrix into a Qobject using Qutip?

asked 2023-06-13 20:59:54 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-13 21:06:02 +0000

devzero gravatar image

There is no direct method in Qutip to convert a sparse matrix into a Qobject. However, you can create a Qobj instance using the qutip.Qobj constructor and passing the sparse matrix as an argument.

Here's an example:

import scipy.sparse as sp
import qutip

# create a sparse matrix
sparse_mat = sp.random(5, 5, density=0.5)

# convert sparse matrix to Qobj
qobj = qutip.Qobj(sparse_mat)

# print Qobj
print(qobj)

This will output something like:

Quantum object: dims = [[5], [5]], shape = (5, 5), type = oper, isherm = False
Qobj data =
[[ 0.34539206+0.j          0.        +0.5881239j   0.        +0.j
   0.        +0.j         -0.08114777+0.j        ]
 [ 0.        +0.5881239j  -0.22347069+0.j          0.        +0.15403432j
   0.        +0.j         -0.09806432+0.j        ]
 [ 0.        +0.j          0.        +0.15403432j  0.47391806+0.j
   0.        +0.j         -0.10039413+0.09877974j]
 [ 0.        +0.j          0.        +0.j          0.        +0.j
  -0.23454739+0.j         -0.10518025+0.j        ]
 [-0.08114777+0.j         -0.09806432+0.j         -0.10039413-0.09877974j
  -0.10518025+0.j         -0.48012117+0.j        ]]

As you can see, the sparse matrix has been converted to a Qobj instance with the same dimensions and shape.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-13 20:59:54 +0000

Seen: 9 times

Last updated: Jun 13 '23