John
John

Reputation: 41

How do I append rows to an array in Python?

I have an array which is a 1X3 matrix, where: column 1 = x coordinate column 2 = y coordinate column 3 = direction of vector.

I am tracking a series of points along a path. At each point i want to store the x,y and direction back into the array, as a row.

So in the end, my array has grown vertically, with more and more rows that represents points along the path.

Im struggling to build this function inside a class. Help plz?

Xx

Upvotes: 0

Views: 865

Answers (4)

Kenly
Kenly

Reputation: 26718

# This is your matrix 1x3
matrix = []

# Use a list to store (x, y, direction)
data = [x, y, direction]

# To add data to the matrix use `append` on matrix list
matrix.append(point)

Upvotes: 0

Mayur Koshti
Mayur Koshti

Reputation: 1862

In [1]: x = [1,2]

In [2]: y = [3,4]

In [3]: x+y
Out[3]: [1, 2, 3, 4]

Upvotes: 0

Michael Aquilina
Michael Aquilina

Reputation: 5520

You're looking for the append function. But you should seriously take a look at numpy for using matrices in python

Upvotes: 2

tombam95
tombam95

Reputation: 343

Use .append('item-goes-here') to append.

Upvotes: 0

Related Questions