# PennyLane for quantum machine learning

**URL:** <https://discuss.pennylane.ai/t/pennylane-for-quantum-machine-learning/766>\
**Category:** PennyLane Help\
**Created:** [January 15, 2021, 1:51pm UTC](https://discuss.pennylane.ai/t/pennylane-for-quantum-machine-learning/766 "2021-01-15T13:51:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sassan\_moradi](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/sassan_moradi/32/422_2.png) [@sassan\_moradi](https://discuss.pennylane.ai/u/sassan_moradi)\
**Post date:** [January 15, 2021, 1:51pm UTC](https://discuss.pennylane.ai/t/pennylane-for-quantum-machine-learning/766/1 "2021-01-15T13:51:30Z")

</div>

Hi.  
i am going to use Mottonenstate preparation method for data encoding. Based on Mottonen state preparation function in Pennylane, number of qubits is equal to log(num\_feature). I used this ‘qml.templates.MottonenStatePreparation(x, wires=[1, 2, 3])’, but i got this error:  
raise ValueError("‘state\_vector’ has to be of length 1.0, got {}".format(norm))  
ValueError: ‘state\_vector’ has to be of length 1.0, got 35.146891102531455.  
do i have to normalize data before using them as an input for MottonenStatePreparation function.

Many thanks

---

<div class="post-metadata">

**Author:** ![glassnotes](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/glassnotes/32/327_2.png) [@glassnotes](https://discuss.pennylane.ai/u/glassnotes)\
**Post date:** [January 15, 2021, 3:17pm UTC](https://discuss.pennylane.ai/t/pennylane-for-quantum-machine-learning/766/2 "2021-01-15T15:17:53Z")

</div>

Hi @sassan_moradi,

Welcome, and thank you for your question!

Yes, the input vectors must be normalized. While this is indicated in the error message, I notice that it is not actually specified in the function documentation, so I’ll make an update to the docs to include this.

Feel free to let us know if you have any further questions!

---

<div class="post-metadata">

**Author:** ![NikSchet](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/nikschet/32/786_2.png) [@NikSchet](https://discuss.pennylane.ai/u/NikSchet)\
**Post date:** [January 27, 2021, 3:20pm UTC](https://discuss.pennylane.ai/t/pennylane-for-quantum-machine-learning/766/3 "2021-01-27T15:20:09Z")

</div>

Does it make sense to try the mottonen state preparation in 2D data? are there any limitations? also can we expand this to 3D or ND data? thanks

---

<div class="post-metadata">

**Author:** ![glassnotes](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/glassnotes/32/327_2.png) [@glassnotes](https://discuss.pennylane.ai/u/glassnotes)\
**Post date:** [January 27, 2021, 4:11pm UTC](https://discuss.pennylane.ai/t/pennylane-for-quantum-machine-learning/766/4 "2021-01-27T16:11:19Z")

</div>

Hi @NikSchet,

As far as I know there are not generalizations to more dimensions, but depending on what you are doing one workaround would be to unroll (flatten) multi-dimensional data down into 1-dimensional data, and use that as the input to state prep.

If you’re interested to discuss further, I encourage you to open a new thread for this topic.
