From: Matt K. <mat...@ho...> - 2006-10-08 05:27:08
|
> Matt Knox wrote:> > Could someone please point me to/provide me with a ba= sic example of > > creating a user defined type?> > > > Here is my complet= ely naive attempt which obviously doesn't work...> >> > import numpy> > > = > class myType(numpy.void):> > def __init__(self,val):> > self.= val =3D val> > > > testType =3D numpy.dtype(myType)> >> > val1 =3D myType(= 5)> > val2 =3D myType(6)> > > > foo =3D numpy.array([val1,val2],testType)>= > > > > > Any help would be greatly appreciated. Thanks,> > =20 > A "true" user-defined data-type can only be done in C.> > However. You c= an 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. =20 I have a custom Date class which allows creation of different frequency Dat= es (annual, monthly, etc..). Two dates of the same frequency can be subtrac= ted, 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. =20 However, the problem with this is that I can't tell the frequency of the Da= tes in the array without inspecting invidual elements of the array, or subc= lassing 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 l= ike a cleaner approach to have these dates defined as data types. =20 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. =20 - Matt =20 _________________________________________________________________ Be one of the first to try Windows Live Mail. http://ideas.live.com/programpage.aspx?versionId=3D5d21c51a-b161-4314-9b0e-= 4911fb2b2e6d= |