## Featured Replies in this Discussion

- by vegaseat

0

Hint, your matrix will be a list of 3 sublists, each sublist has 4 elements.

```
matrix34 = [
[2.5, 3.0, 4.0, 1.5],
[1.5, 4.0, 2.0, 7.5],
[3.5, 1.0, 1.0, 2.5]
]
```

Each sublist forms a row and each column has matching index number elements from each sublist. The index is zero based, so column one has index 0. The value in row three and column one is matrix34[2][0] --> 3.5

0

this is easy to do :

```
#!/usr/bin/env python
#-*- coding:utf-8 -*-
matirx = []
for i in xrange(3):
print "Enter a 3-by 4 matrix row for row %d" % i
row = map(float, raw_input().split(' '))
matirx.append(row)
print "The matrix is"
for row in matirx:
print row
revmatirx = map(list, zip(*matirx))
for i in xrange(4):
print "Sum of elements for column %d is" % i
print sum(revmatirx[i])
```

0

Also, if this is just an exercise, then doing it with native python datastructures (like lists) is a nice way to go. In reality, you should use numpy to make a matrix. It's a library for just this, and will be about 1000 times faster than a matrix made out of python datastructures, due to its c-level optimizations.

1

For a dictionary approach see:

http://www.daniweb.com/software-development/python/code/446042/a-matrix-dictionary-python

You

This question has already been solved: Start a new discussion instead