I am new at QC. I learn from a course. When I write to this code:

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
q = QuantumRegister (1)
c = ClassicalRegister(1)
qc = QuantumCircuit(q,c)

from qiskit.quantum_info import Statevector

psi1 = Statevector(qc)


I am gettin an error :

> QiskitError                               Traceback (most recent call
> last) <ipython-input-28-eccf64e782f7> in <module>
> ----> 1 psi1 = Statevector(qc)
>       2 psi1.draw('latex')
> C:\ProgramData\Anaconda3\lib\site-packages\qiskit\quantum_info\states\statevector.py
> in __init__(self, data, dims)
>      72             self._data = np.ravel(data.data)
>      73         else:
> ---> 74             raise QiskitError("Invalid input data format for Statevector")
>      75         # Check that the input is a numpy vector or column-vector numpy
>      76         # matrix. If it is a column-vector matrix reshape to a vector.
> QiskitError: 'Invalid input data format for Statevector'

Can you help me?

thanks your time.

  • $\begingroup$ Does the variable qc refer to an instance of QuantumCircuit? $\endgroup$ Jun 8, 2022 at 14:48
  • $\begingroup$ Can you please share the complete code?qc needs to be an instance of a QuantumCircuit. $\endgroup$
    – sohamb172
    Jun 8, 2022 at 15:02
  • $\begingroup$ I am sorry, I am fixing it now $\endgroup$
    – Oilon
    Jun 9, 2022 at 6:05
  • $\begingroup$ This code worked with me with no issues. What version of Qiskit do you have? $\endgroup$ Jun 9, 2022 at 6:40
  • $\begingroup$ I use jupyter notebook on anaconda. when I install I wrote "pip install qiskit" on CMD.exe of anaconda. $\endgroup$
    – Oilon
    Jun 9, 2022 at 9:29

1 Answer 1


Tips for you to understand error:

  • take a look at qiskit docs, what is the valid data input, learn more about Statevector class
  • and from output error
    QiskitError: 'Invalid input data format for Statevector'
    which mean you didn't input the expected data(np.array or list or Statevector or Operator or QuantumCircuit)
  • check sources code if it make sense, and discuss in StackExchange or slack then report bug to github sources code, if there is any bug.

I hope these tips help you though study QC.
also please provide more info about your input for Statevector, if you need any help.

  • $\begingroup$ Thanks for your interest. I edited my question and I added the complete code. May you help me now? Thanks you again. $\endgroup$
    – Oilon
    Jun 9, 2022 at 6:10
  • $\begingroup$ @Oilon it works for me, you can try to reinstall qiskit-terra. or Check the source code, if statement check is correct. $\endgroup$
    – poig
    Jun 10, 2022 at 0:12
  • $\begingroup$ Thanks for your answer. I solve my problem. I deleted everything and reinstall it worked. $\endgroup$
    – Oilon
    Jun 10, 2022 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.