next up previous contents
Next: Tests of interaction with Up: Getting started and examples Previous: Tests of elementwise operations   Contents

Tests of the shape attribute

The file test_shape.py reveals shapes of various objects. Results are at 3.7


#!/usr/bin/env python
# (C) 2000 Huaiyu Zhu <hzhu@users.sourceforge.net>.  Licence: GPL
# $Id: test_shape.py,v 1.1.1.1 2000/06/03 23:56:50 hzhu Exp $
"""
Test various shapes
"""

from MatPy.Matrix import *

a = Matrix(1)
print a, a.shape

b = Matrix([1])
print b, b.shape

c = Matrix([[1]])
print c, c.shape

try:
	d = Matrix([[[1]]])
	print d, d.shape
except ValueError:
	print "This does not work, as expected"

print "-"*40

a = Matrix(range(3))
print a, a.shape

b = Matrix([range(3)])
print b, b.shape

try:
	c = Matrix([[range(3)]])
	print c, c.shape
except ValueError:
	print "This does not work, as expected"

print b[0]
print b[1]
print b[2]
print b[0,0]
print b[0,1]
print b[0,2]

print "-"*40

a = Matrix([])
print a, a.shape

b = Matrix([[]])
print b, b.shape

try:
	c = Matrix([[[]]])
	print c, c.shape
except ValueError:
	print "This does not work, as expected"



Result obtained with
>>> from MatPy.tests import test_shape


[ 1  ] (1, 1)
[ 1  ] (1, 1)
[ 1  ] (1, 1)
This does not work, as expected
----------------------------------------
[ 0   1   2  ] (1, 3)
[ 0   1   2  ] (1, 3)
This does not work, as expected
0
1
2
0
1
2
----------------------------------------
[ ] (1, 0)
[ ] (1, 0)
This does not work, as expected



Huaiyu Zhu
2002-03-23