Skip to content
Snippets Groups Projects
Commit b6862320 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
Browse files

Add examples to vstack_features too so they get tested

parent 6298fa61
No related branches found
No related tags found
1 merge request!82Add a function to read features with generators
Pipeline #
...@@ -289,6 +289,49 @@ def vstack_features(reader, paths, same_size=False): ...@@ -289,6 +289,49 @@ def vstack_features(reader, paths, same_size=False):
------- -------
numpy.ndarray numpy.ndarray
The read features with the shape (n_samples, \*features_shape[1:]). The read features with the shape (n_samples, \*features_shape[1:]).
Examples
--------
This function is equivalent to calling
``numpy.vstack(reader(p) for p in paths)``.
>>> import numpy
>>> from bob.bio.base import vstack_features
>>> def reader(path):
... # in each file, there are 5 samples and features are 2 dimensional.
... return numpy.arange(10).reshape(5,2)
>>> paths = ['path1', 'path2']
>>> all_features = vstack_features(reader, paths)
>>> all_features
array([[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9],
[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9]])
>>> all_features_with_more_memory = numpy.vstack(reader(p) for p in paths)
>>> numpy.allclose(all_features, all_features_with_more_memory)
True
You can allocate the array at once to improve the performance if you know
that all features in paths have the same shape and you know the total number
of the paths:
>>> vstack_features(reader, paths, same_size=True)
array([[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9],
[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9]])
""" """
iterable = _generate_features(reader, paths) iterable = _generate_features(reader, paths)
dtype = next(iterable) dtype = next(iterable)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment