# How do I encode a classical vector into the input qubits?

Does anyone know how to encode a classical vector into a quantum state? For instance, I would like to encoder a classical vector $$(0, 0.1, 0.4, 0.9)$$ into 2 qubits by adding some quantum gates on 2 $$|0\rangle$$ starting states. Any program package including Qiskit, pyquil, cirq... is fine.

• while there are common, "standard" ways to do this, I would note that in principle you can encode information however you like in the quantum state. You are not in principle bounded to encode it into the amplitudes
– glS
Commented Jun 27, 2020 at 15:41

I think you should look for quantum amplitude encoding strategies. A nice and practical tutorial (with reference to Qiskit) is the following one by Maria Schuld:

https://medium.com/qiskit/building-the-worlds-smallest-quantum-classifier-7da7cd845b84

Interesting (but more advanced) articles are also:

https://www.nature.com/articles/s41598-019-40439-3

https://arxiv.org/abs/1907.02085

Firstly, you have to normalize your vector $$x$$ to have an Euclidian norm equal one, i.e.

$$||x||=||(0,0.1,0.4,0.9)|| = \sqrt{0^2 + 0.1^2 +0.4^2+0.9^2} = \sqrt{0.98}$$

So, your vector representing a quantum state is $$\frac{1}{\sqrt{0.98}}(0,0.1,0.4,0.9).$$

Now, you can apply methods described in this thread.