Note
Go to the end to download the full example code.
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:['0x17f629d50']
Shape: (1,)
Values: [0.]
Min: 0.0
Max: 0.0
DataArray
Name: 10
Address:['0x17f629450']
Shape: (10,)
Values: [0. 0. 0. ... 0. 0. 0.]
Min: 0.0
Max: 0.0
DataArray
Name: (2, 10)
Address:['0x17f62aad0']
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:['0x154ab7a50']
Shape: (2,)
Values: [ 2 10]
Min: 2
Max: 10
DataArray
Name: 45.454
Address:['0x154ab6dd0']
Shape: (1,)
Values: [45.454]
Min: 45.454
Max: 45.454
DataArray
Name: 45.454
Address:['0x17f62aad0']
Shape: (1,)
Values: [45.454]
Min: 45.454
Max: 45.454
DataArray
Name: test ($\frac{g}{cc}$)
Address:['0x154ab6dd0']
Shape: (1,)
Values: [0.00257118]
Min: 0.002571182431510025
Max: 0.002571182431510025
DataArray
Name: test ($\frac{g}{cc}$)
Address:['0x17f62aad0']
Shape: (10,)
Values: [0. 1. 2. ... 7. 8. 9.]
Min: 0.0
Max: 9.0
DataArray
Name: test ($\frac{g}{cc}$)
Address:['0x154ab7a50']
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.003 seconds)