DataArray Class

Extends the numpy ndarray class to add extra attributes such as names, and units, and allows us to attach statistical descriptors of the array. The direct extension to numpy maintains speed and functionality of numpy arrays.

DataArray
Name:   1
Address:['0x1455d7b50']
Shape:  (1,)
Values: [0.]
Min:    0.0
Max:    0.0

DataArray
Name:   10
Address:['0x1455d45d0']
Shape:  (10,)
Values: [0. 0. 0. ... 0. 0. 0.]
Min:    0.0
Max:    0.0

DataArray
Name:   (2, 10)
Address:['0x10e47ce50']
Shape:  (2, 10)
Values: [[0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]]
Min:    0.0
Max:    0.0

DataArray
Name:   (2, 10)
Address:['0x10e47d3d0']
Shape:  (2,)
Values: [ 2 10]
Min:    2
Max:    10

DataArray
Name:   45.454
Address:['0x10e463bd0']
Shape:  (1,)
Values: [45.454]
Min:    45.454
Max:    45.454

DataArray
Name:   45.454
Address:['0x10e47d550']
Shape:  (1,)
Values: [45.454]
Min:    45.454
Max:    45.454

DataArray
Name:   test ($\frac{g}{cc}$)
Address:['0x10e47d3d0']
Shape:  (1,)
Values: [1.2639152]
Min:    1.2639151990006638
Max:    1.2639151990006638

DataArray
Name:   test ($\frac{g}{cc}$)
Address:['0x10e47d550']
Shape:  (10,)
Values: [0. 1. 2. ... 7. 8. 9.]
Min:    0.0
Max:    9.0

DataArray
Name:   test ($\frac{g}{cc}$)
Address:['0x10e460250']
Shape:  (10,)
Values: [0. 1. 2. ... 7. 8. 9.]
Min:    0.0
Max:    9.0

import  numpy as np
from geobipy import DataArray, StatArray

# Integer
test = DataArray(1, name='1')
assert isinstance(test, DataArray) and test.size ==  1 and test.item() == 0.0, TypeError("da 0")
print(test.summary)
test = DataArray(10, name='10')
assert isinstance(test, DataArray) and test.size ==  10 and np.all(test == 0.0), TypeError("da 1")
print(test.summary)
# tuple/Shape
test = DataArray((2, 10), name='(2, 10)')
assert isinstance(test, DataArray) and np.all(test.shape ==  (2, 10)) and np.all(test == 0.0), TypeError("da 2")
print(test.summary)

test = DataArray([2, 10], name='(2, 10)')
assert isinstance(test, DataArray) and np.all(test ==  [2, 10]), TypeError("da 2")
print(test.summary)

# float
test = DataArray(45.454, name='45.454')
assert isinstance(test, DataArray) and test.size ==  1 and test.item() == 45.454, TypeError("da 3")
print(test.summary)
test = DataArray(np.float64(45.454), name='45.454')
assert isinstance(test, DataArray) and test.size ==  1 and test.item() == 45.454, TypeError("da 4")
print(test.summary)

# array
test = DataArray(np.random.randn(1), name="test", units="$\frac{g}{cc}$")
assert isinstance(test, DataArray) and test.size ==  1, TypeError("da 5")
print(test.summary)

test = DataArray(np.arange(10.0), name="test", units="$\frac{g}{cc}$")
assert isinstance(test, DataArray) and test.size ==  10, TypeError("da 6")
print(test.summary)

test = DataArray(test)
assert isinstance(test, DataArray) and test.size ==  10, TypeError("da 6")
print(test.summary)

Total running time of the script: (0 minutes 0.004 seconds)

Gallery generated by Sphinx-Gallery