# Vectors in Python

**URL:** <https://discourse.codecombat.com/t/vectors-in-python/1031>\
**Category:** Archmage\
**Created:** [July 28, 2014, 11:50pm UTC](https://discourse.codecombat.com/t/vectors-in-python/1031 "2014-07-28T23:50:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DollarAkshay](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@DollarAkshay](https://discourse.codecombat.com/u/DollarAkshay)\
**Post date:** [July 28, 2014, 11:50pm UTC](https://discourse.codecombat.com/t/vectors-in-python/1031/1 "2014-07-28T23:50:06Z")

</div>

How do I create Vectors in python ?

```
px = self.pos.x;
py = self.pos.y;
v = Vector(px-target.pos.x, py-target.pos.y)
self.move({'x': px+v.x, 'y': py+v.y})

```

Apparently this dosen’t work.I tried adding the `new` keyword,that also dint help  
I would like to know how to normalize them too

---

<div class="post-metadata">

**Author:** ![differentmatt](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/differentmatt/32/10258_2.png) [@differentmatt](https://discourse.codecombat.com/u/differentmatt)\
**Post date:** [August 2, 2014, 6:46pm UTC](https://discourse.codecombat.com/t/vectors-in-python/1031/2 "2014-08-02T18:46:22Z")

</div>

Vector isn’t support in Python yet. A workaround is to write your own Vector class for now.

I’ve opened an issue to track this problem:

> <https://github.com/codecombat/codecombat/issues/1403>
>
> The Python parser doesn't know that Vector is an available class, so it calls the Vector method instead.
> Python needs to know...

---

<div class="post-metadata">

**Author:** ![Arunabha\_Sarkar](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/arunabha_sarkar/32/3019_2.png) [@Arunabha\_Sarkar](https://discourse.codecombat.com/u/Arunabha_Sarkar)\
**Post date:** [October 9, 2015, 7:42pm UTC](https://discourse.codecombat.com/t/vectors-in-python/1031/3 "2015-10-09T19:42:00Z")

</div>

Hi,

```python
distance = Vector.subtract(self.pos, yak) 

```

&

```python
distance = Vector.subtract(yak, self.pos)

```

The first statement works correctly, the second shows an error (same place in the code). Why so?

---

<div class="post-metadata">

**Author:** ![ant](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ant/32/3362_2.png) [@ant](https://discourse.codecombat.com/u/ant)\
**Post date:** [October 9, 2015, 9:01pm UTC](https://discourse.codecombat.com/t/vectors-in-python/1031/4 "2015-10-09T21:01:43Z")

</div>

> [@Arunabha\_Sarkar](#):
>
> `distance = Vector.subtract(self.pos, yak)`
> 
> `distance = Vector.subtract(yak, self.pos)`
> 
> The first statement works correctly, the second shows an error (same place in the code). Why so?

I don’t know why any of those work, because `yak` would be a name or an id. Try to replace `yak` with `yak.pos` and they should be OK.

---

<div class="post-metadata">

**Author:** ![Arunabha\_Sarkar](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/arunabha_sarkar/32/3019_2.png) [@Arunabha\_Sarkar](https://discourse.codecombat.com/u/Arunabha_Sarkar)\
**Post date:** [October 10, 2015, 7:18am UTC](https://discourse.codecombat.com/t/vectors-in-python/1031/5 "2015-10-10T07:18:11Z")

</div>

Thanks, it worked. Guess I am very new to vectors
