***[Possible UCE]*** user-defined type example

Matt Knox mattknox_ca at hotmail.com
Sun Oct 8 01:27:02 EDT 2006


> Matt Knox wrote:> > Could someone please point me to/provide me with a basic example of > > creating a user defined type?> >  > > Here is my completely naive attempt which obviously doesn't work...> >> > import numpy> >  > > class myType(numpy.void):> >     def __init__(self,val):> >         self.val = val> >  > > testType = numpy.dtype(myType)> >> > val1 = myType(5)> > val2 = myType(6)> >  > > foo = numpy.array([val1,val2],testType)> >  > >  > > Any help would be greatly appreciated. Thanks,> >  
> A "true" user-defined data-type can only be done in C.> > However.  You can use the "VOID" data-type to create a type with > multiple fields.   What do you want to do with your user-defined data-type.>> -Travis
Thanks for the reply Travis.
 
I have a custom Date class which allows creation of different frequency Dates (annual, monthly, etc..). Two dates of the same frequency can be subtracted, and integers can be added to a Date, with the obvious results in each case.  I store these dates in arrays currently using the "object" dtype.
 
However, the problem with this is that I can't tell the frequency of the Dates in the array without inspecting invidual elements of the array, or subclassing the array object itself. I'd like to be able to have each frequency of date as a data type  (DateAnnual, DateMonthly, etc...). It just seems like a cleaner approach to have these dates defined as data types.
 
I would be open to the idea of defining this in C, but I don't really have any examples to work with for that either.
Many thanks for any advice/suggestions you can provide.
 
- Matt
 
_________________________________________________________________
Be one of the first to try Windows Live Mail.
http://ideas.live.com/programpage.aspx?versionId=5d21c51a-b161-4314-9b0e-4911fb2b2e6d
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20061008/4f0fb372/attachment.html>
-------------- next part --------------
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
-------------- next part --------------
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion


More information about the NumPy-Discussion mailing list