Created
January 27, 2010 10:24
-
-
Save shelling/287716 to your computer and use it in GitHub Desktop.
using numpy.ndarray to construct Plane class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| #-*- mode: python -*- | |
| import numpy | |
| class Plane(numpy.ndarray): | |
| """ | |
| """ | |
| def __new__(cls, abuffer): | |
| abuffer = numpy.array(abuffer, dtype="float128") | |
| if len(abuffer.shape) == 2: | |
| return numpy.ndarray.__new__(cls, abuffer.shape, "float128", abuffer) | |
| else: | |
| pass | |
| def __array_finalize__(self, obj): | |
| pass | |
| @property | |
| def name(self, name): | |
| self.name = name | |
| return self | |
| p = Plane([[1,2,],[3,4]]) | |
| print p | |
| print p.shape | |
| print p.dtype | |
| print p.__class__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment