Search This Blog

Monday, April 4, 2011

Matrix operations using numpy


# This example shows how a matrix can be read from terminal and to do various operations
from numpy import *
print "Enter order of matrix"
m=input("Rows=")
n=input("Columns=")
xx=zeros([m,n],float)
print "enter matrix elements"
for i in range(m):
    print "Enter elements of row ",i+1
    for j in range(n):
        xx[i][j]=input()

print "xx \n",xx
print
print "xx+2 \n",xx+2
print
print "xx+xx \n",xx+xx
print
print "xx*xx \n",xx*xx
print
print "xx-xx \n",xx-xx
print
print "xx*2 \n",xx*2
print
print "xx/xx \n",xx/xx