# Encoding package¶

## qiskit_quantum_knn.encoding.analog module¶

encode(classical_data)[source]

Encodes the given classical state to a quantum state.

The encoding of a state makes sure that the following rule within quantum mechanics is met:

$\langle \psi | \psi \rangle = 1,$

for a quantum state $$\psi$$. To put it in other words, suppose that $$\psi = \sum_i c_i x_i$$ with $$c_i \in \mathbb{C}$$, the encoding will normalise the values $$c_i$$ such that $$\sum_i |c_i|^2 = 1$$.

Example

Simple encoding using real values.

from qiskit_quantum_knn.encoding.analog import encode

classical_state = [
[1, 1, 1, 1]
]
normalised_state = encode(classical_state)

print(normalised_state)
print((normalised_state ** 2).sum())

[[0.5 0.5 0.5 0.5]]
1.0


Using complex values.

classical_state = [
[1+2j, 1-3j, 1+2j, 1+3j]
]
normalised_state = encode(classical_state)

print(normalised_state)
print((normalised_state ** 2).sum())

[[ 0.44295684-0.1318281j  -0.57478495-0.31112874j  0.44295684-0.1318281j
0.6465052 -0.09596798j]]
(1-2.7755575615628914e-17j)

Parameters

classical_data (vector_like) – state(s) to encode.

Returns

the encoded quantum state.

Return type

np.ndarray