Last change
on this file since 1951 was
1910,
checked in by ole, 19 years ago
|
Made utilities a Python package
Added numerical_tools (and test) containing ensure_numeric from the old util module.
Added test_polygon.py
|
File size:
1.0 KB
|
Line | |
---|
1 | #!/usr/bin/env python |
---|
2 | """Auxiliary numerical tools |
---|
3 | |
---|
4 | """ |
---|
5 | |
---|
6 | |
---|
7 | def ensure_numeric(A, typecode = None): |
---|
8 | """Ensure that sequence is a Numeric array. |
---|
9 | Inputs: |
---|
10 | A: Sequence. If A is already a Numeric array it will be returned |
---|
11 | unaltered |
---|
12 | If not, an attempt is made to convert it to a Numeric |
---|
13 | array |
---|
14 | typecode: Numeric type. If specified, use this in the conversion. |
---|
15 | If not, let Numeric decide |
---|
16 | |
---|
17 | This function is necessary as array(A) can cause memory overflow. |
---|
18 | """ |
---|
19 | |
---|
20 | from Numeric import ArrayType, array |
---|
21 | |
---|
22 | if typecode is None: |
---|
23 | if type(A) == ArrayType: |
---|
24 | return A |
---|
25 | else: |
---|
26 | return array(A) |
---|
27 | else: |
---|
28 | if type(A) == ArrayType: |
---|
29 | if A.typecode == typecode: |
---|
30 | return array(A) #FIXME: Shouldn't this just return A? |
---|
31 | else: |
---|
32 | return A.astype(typecode) |
---|
33 | else: |
---|
34 | return array(A).astype(typecode) |
---|
35 | |
---|
Note: See
TracBrowser
for help on using the repository browser.