Does anyone have an idea about implementing two dimensional arrays in Python??

I want to write two programs:
(1) a program for matrix multiplication
(2) a program for displaying Pascal's triangle.

Both these programs require two dimensional array..? Or is there any other way to solve this..
Thanks in anticipation..

A Kadri

Recommended Answers

All 3 Replies

You can define matrix using list:

matrix = [[1,2,3],[4,5,6],[7,8,9]]

print matrix[0][1]

As for multiplication program and Pascal's triangle, you'll need to show some effort. Matrix is not needed for displaying Pascal's triangle

There are modules like numpy, that do high speed array and matrix manipulations. Google for numpy, its free.

Pascal's triangle is most easily done using recursion, IMO.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.