This commit is contained in:
44
script/test/TestMultiDimens.py
Normal file
44
script/test/TestMultiDimens.py
Normal file
@@ -0,0 +1,44 @@
|
||||
def append_dataset(path, data, index=None, type='d', shape=None):
|
||||
"""Append data to dataset.
|
||||
|
||||
Args:
|
||||
path(str): Path to dataset relative to the current persistence context root.
|
||||
data(number or array or list): name of each column.
|
||||
index(int or list, optional): if set then add the data in a specific position in the dataset.
|
||||
If integer is the index in an array (data must be 1 order lower than dataset)
|
||||
If a list, specifies the full coordinate for multidimensional datasets.
|
||||
type(str, optional): array type 'b' = byte, 'h' = short, 'i' = int, 'l' = long, 'f' = float,
|
||||
'd' = double, 'c' = char, 's' = String, 'o' = Object
|
||||
default: 'd' (convert data to array of doubles)
|
||||
shape(list, optional): only valid if index is a list, provides the shape of the data array.
|
||||
In this case data must be a flattened one-dimensional array.
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
data = to_array(data, type)
|
||||
|
||||
if index is None:
|
||||
get_context().dataManager.appendItem(path, data)
|
||||
else:
|
||||
if is_list(index):
|
||||
if shape is None:
|
||||
shape = [len(index)]
|
||||
get_context().dataManager.setItem(path, data, index, shape)
|
||||
else:
|
||||
get_context().dataManager.setItem(path, data, index)
|
||||
|
||||
|
||||
path = "data/data4d"
|
||||
data3d = [ [ [1,2,3,4,5], [2,3,4,5,6], [3,4,5,6,7], [4,5,6,7,8]],
|
||||
[ [2,2,3,4,5], [3,3,4,5,6], [5,4,5,6,7], [7,5,6,7,8]],
|
||||
[ [3,2,3,4,5], [4,3,4,5,6], [6,4,5,6,7], [8,5,6,7,8]] ]
|
||||
|
||||
plot(data3d)
|
||||
|
||||
data = flatten(to_array(data3d,'i))
|
||||
|
||||
|
||||
|
||||
#save_dataset(path, data4d)
|
||||
create_dataset(path, 'i', dimensions = [2, 3, 4, 5])
|
||||
append_dataset(path, data, index = [0,0,0,0], type = 'i', shape=[1, 3, 4, 5])
|
||||
Reference in New Issue
Block a user