batoolset 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- batoolset/GUI/__init__.py +0 -0
- batoolset/GUI/list_gui.py +513 -0
- batoolset/GUI/multi_image_display.py +989 -0
- batoolset/GUI/open.py +325 -0
- batoolset/GUI/overlay_hints.py +45 -0
- batoolset/GUI/paint2.py +1345 -0
- batoolset/GUI/scrollablepaint.py +1152 -0
- batoolset/IJ_ROIs/__init__.py +0 -0
- batoolset/IJ_ROIs/tools.py +40 -0
- batoolset/PATH/__init__.py +0 -0
- batoolset/PATH/tools.py +79 -0
- batoolset/SQLite_tools/__init__.py +0 -0
- batoolset/SQLite_tools/tools.py +840 -0
- batoolset/__init__.py +0 -0
- batoolset/binary/__init__.py +0 -0
- batoolset/binary/tools.py +123 -0
- batoolset/binarytools/__init__.py +0 -0
- batoolset/binarytools/cell_center_detector.py +290 -0
- batoolset/clipboard_tools/__init__.py +0 -0
- batoolset/clipboard_tools/tools.py +7 -0
- batoolset/colors/__init__.py +0 -0
- batoolset/colors/colorgen.py +193 -0
- batoolset/colors/tools.py +22 -0
- batoolset/command_line/__init__.py +0 -0
- batoolset/command_line/tools.py +18 -0
- batoolset/dialogs/__init__.py +0 -0
- batoolset/dialogs/opensave.py +228 -0
- batoolset/dicts/__init__.py +0 -0
- batoolset/dicts/tools.py +299 -0
- batoolset/dims/__init__.py +0 -0
- batoolset/dims/tools.py +83 -0
- batoolset/draw/__init__.py +0 -0
- batoolset/draw/shapes/Position.py +183 -0
- batoolset/draw/shapes/__init__.py +0 -0
- batoolset/draw/shapes/automated_alignment_drawing_refactored.py +346 -0
- batoolset/draw/shapes/circle2d.py +99 -0
- batoolset/draw/shapes/compute_optimal_size_all_merged.py +317 -0
- batoolset/draw/shapes/ellipse2d.py +336 -0
- batoolset/draw/shapes/freehand2d.py +235 -0
- batoolset/draw/shapes/group.py +1830 -0
- batoolset/draw/shapes/image2d.py +2469 -0
- batoolset/draw/shapes/line2d.py +575 -0
- batoolset/draw/shapes/point2d.py +257 -0
- batoolset/draw/shapes/polygon2d.py +357 -0
- batoolset/draw/shapes/polyline2d.py +235 -0
- batoolset/draw/shapes/rect2d.py +388 -0
- batoolset/draw/shapes/rectangle2d.py +601 -0
- batoolset/draw/shapes/scalebar.py +304 -0
- batoolset/draw/shapes/serializablefont.py +126 -0
- batoolset/draw/shapes/serializableguiparams.py +10 -0
- batoolset/draw/shapes/square2d.py +103 -0
- batoolset/draw/shapes/textorientation.py +45 -0
- batoolset/draw/shapes/tools.py +467 -0
- batoolset/draw/shapes/transform2D.py +350 -0
- batoolset/draw/shapes/txt2d.py +550 -0
- batoolset/draw/widgets/__init__.py +0 -0
- batoolset/draw/widgets/col.py +343 -0
- batoolset/draw/widgets/image_group.py +248 -0
- batoolset/draw/widgets/image_organizer.py +96 -0
- batoolset/draw/widgets/paint.py +184 -0
- batoolset/draw/widgets/vectorial.py +257 -0
- batoolset/figure/__init__.py +0 -0
- batoolset/figure/alignment.py +814 -0
- batoolset/figure/column.py +1117 -0
- batoolset/figure/fig_tools.py +285 -0
- batoolset/figure/minimal_debugger_scale_etc.py +139 -0
- batoolset/figure/panel.py +697 -0
- batoolset/figure/row.py +852 -0
- batoolset/figure/user_selection.py +287 -0
- batoolset/files/__init__.py +0 -0
- batoolset/files/tools.py +1321 -0
- batoolset/images/__init__.py +0 -0
- batoolset/images/tools.py +81 -0
- batoolset/img.py +5216 -0
- batoolset/linux/__init__.py +0 -0
- batoolset/linux/tools.py +72 -0
- batoolset/lists/__init__.py +0 -0
- batoolset/lists/tools.py +436 -0
- batoolset/luts/__init__.py +0 -0
- batoolset/luts/lut_minimal_test.py +1207 -0
- batoolset/matplolib/__init__.py +0 -0
- batoolset/matplolib/tools.py +44 -0
- batoolset/np_tools/__init__.py +0 -0
- batoolset/np_tools/tools.py +252 -0
- batoolset/np_tools/trash.py +15 -0
- batoolset/pandas_tools/__init__.py +0 -0
- batoolset/pandas_tools/tools.py +880 -0
- batoolset/partials/__init__.py +0 -0
- batoolset/partials/tools.py +83 -0
- batoolset/plot_tools/__init__.py +0 -0
- batoolset/plot_tools/tools.py +70 -0
- batoolset/pyqt/__init__.py +0 -0
- batoolset/pyqt/tools.py +691 -0
- batoolset/re_tools/__init__.py +0 -0
- batoolset/re_tools/tools.py +35 -0
- batoolset/serialization/__init__.py +0 -0
- batoolset/serialization/tools.py +1192 -0
- batoolset/sets/__init__.py +0 -0
- batoolset/sets/tools.py +109 -0
- batoolset/settings/__init__.py +0 -0
- batoolset/settings/global_settings.py +134 -0
- batoolset/strings/__init__.py +0 -0
- batoolset/strings/tools.py +225 -0
- batoolset/ta/__init__.py +0 -0
- batoolset/ta/database/__init__.py +0 -0
- batoolset/ta/database/advanced_sql_plotter.py +1170 -0
- batoolset/ta/database/my_qt_table.py +79 -0
- batoolset/ta/database/preview_and_edit_sqlite_db.py +405 -0
- batoolset/ta/database/sql.py +2141 -0
- batoolset/ta/database/sql_column_name_dialog.py +122 -0
- batoolset/ta/measurements/TAmeasures.py +2226 -0
- batoolset/ta/measurements/__init__.py +0 -0
- batoolset/ta/measurements/measurements3D/__init__.py +0 -0
- batoolset/ta/measurements/measurements3D/get_point_on_surface_if_centroid_is_bad.py +175 -0
- batoolset/ta/measurements/measurements3D/height_map_to_projection.py +82 -0
- batoolset/ta/measurements/measurements3D/measures3D.py +208 -0
- batoolset/ta/measurements/measurements3D/triangulate.py +331 -0
- batoolset/ta/measurements/nematic.py +562 -0
- batoolset/ta/measurements/nematic_measurements.py +107 -0
- batoolset/ta/segmentation/__init__.py +0 -0
- batoolset/ta/segmentation/neo_wshed.py +314 -0
- batoolset/ta/selections/__init__.py +0 -0
- batoolset/ta/selections/selection.py +329 -0
- batoolset/ta/tracking/__init__.py +0 -0
- batoolset/ta/tracking/last_tracking_based_on_matching_or_on_translation_from_mermaid_warp.py +653 -0
- batoolset/ta/tracking/local_to_track_correspondance.py +138 -0
- batoolset/ta/tracking/rapid_detection_of_vertices.py +517 -0
- batoolset/ta/tracking/registration.py +108 -0
- batoolset/ta/tracking/swap_detector_and_fixer.py +296 -0
- batoolset/ta/tracking/track_correction.py +238 -0
- batoolset/ta/tracking/tracking_error_detector_and_fixer.py +3099 -0
- batoolset/ta/tracking/tracking_yet_another_approach_pyramidal_registration_n_neo_swapping_correction.py +725 -0
- batoolset/ta/utils/TA_tools.py +43 -0
- batoolset/ta/utils/__init__.py +0 -0
- batoolset/ta/utils/rps_tools.py +1783 -0
- batoolset/tests/__init__.py +0 -0
- batoolset/tests/rps_tools.py +51 -0
- batoolset/tests/tools.py +10 -0
- batoolset/tools/__init__.py +0 -0
- batoolset/tools/early_stopper_class.py +9 -0
- batoolset/tools/guided_data_recoverer.py +110 -0
- batoolset/tools/logger.py +100 -0
- batoolset/tools/mytimer.py +31 -0
- batoolset/tools/prompt_color.py +160 -0
- batoolset/tools/qthandler.py +118 -0
- batoolset/uitools/__init__.py +0 -0
- batoolset/uitools/blinker.py +56 -0
- batoolset/unsafe/__init__.py +0 -0
- batoolset/unsafe/tools.py +115 -0
- batoolset/utils/__init__.py +0 -0
- batoolset/utils/commontools.py +158 -0
- batoolset/utils/loadlist.py +728 -0
- batoolset/version.py +10 -0
- batoolset/xml/__init__.py +0 -0
- batoolset/xml/tools.py +65 -0
- batoolset/zip_tools/__init__.py +0 -0
- batoolset/zip_tools/tools.py +76 -0
- batoolset-0.1.0.dist-info/LICENSE +24 -0
- batoolset-0.1.0.dist-info/METADATA +45 -0
- batoolset-0.1.0.dist-info/RECORD +162 -0
- batoolset-0.1.0.dist-info/WHEEL +5 -0
- batoolset-0.1.0.dist-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from batoolset.settings.global_settings import set_UI # set the UI to qtpy
|
|
2
|
+
set_UI()
|
|
3
|
+
import matplotlib.pyplot as plt
|
|
4
|
+
from qtpy.QtCore import QRectF
|
|
5
|
+
|
|
6
|
+
def get_fig_rect(fig: plt.Figure) -> QRectF:
|
|
7
|
+
"""
|
|
8
|
+
Get the size of the Matplotlib figure in pixels and return it as a QRectF object.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
fig (plt.Figure): The Matplotlib figure.
|
|
12
|
+
|
|
13
|
+
Returns:
|
|
14
|
+
QRectF: A QRectF object representing the figure size in pixels.
|
|
15
|
+
"""
|
|
16
|
+
# Get the figure size in inches
|
|
17
|
+
fig_size_inches = fig.get_size_inches()
|
|
18
|
+
|
|
19
|
+
# Get the figure DPI
|
|
20
|
+
fig_dpi = fig.get_dpi()
|
|
21
|
+
|
|
22
|
+
# Convert the figure size to pixels
|
|
23
|
+
fig_size_pixels = fig_size_inches * fig_dpi
|
|
24
|
+
|
|
25
|
+
# Create a QRectF object using the figure size in pixels
|
|
26
|
+
fig_rect = QRectF(0, 0, fig_size_pixels[0], fig_size_pixels[1])
|
|
27
|
+
|
|
28
|
+
return fig_rect
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
if __name__ == '__main__':
|
|
32
|
+
import numpy as np
|
|
33
|
+
|
|
34
|
+
t = np.arange(0.0, 2.0, 0.01)
|
|
35
|
+
s = 1 + np.sin(2 * np.pi * t)
|
|
36
|
+
|
|
37
|
+
fig, ax = plt.subplots()
|
|
38
|
+
ax.plot(t, s)
|
|
39
|
+
|
|
40
|
+
ax.set(xlabel='time (s)', ylabel='voltage (mV)', title=None)
|
|
41
|
+
ax.grid()
|
|
42
|
+
|
|
43
|
+
fig_rect = get_fig_rect(fig)
|
|
44
|
+
print(fig_rect)
|
|
File without changes
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# here I will put numpy tips
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
import matplotlib.pyplot as plt
|
|
5
|
+
import numpy as np
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
def get_value_from_nd_coords(img, nd_coords):
|
|
9
|
+
"""
|
|
10
|
+
Retrieves the value from an image at the specified N-dimensional coordinates.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
img (numpy.ndarray): The input image.
|
|
14
|
+
nd_coords (numpy.ndarray): The N-dimensional coordinates.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
int or float: The value at the specified coordinates.
|
|
18
|
+
|
|
19
|
+
Examples:
|
|
20
|
+
>>> img = np.array([[1, 2], [3, 4]])
|
|
21
|
+
>>> nd_coords = np.array([[0, 1], [1, 0]])
|
|
22
|
+
>>> result = get_value_from_nd_coords(img, nd_coords)
|
|
23
|
+
>>> print(result)
|
|
24
|
+
[2, 3]
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
return img[convert_nd_coords_to_numpy_format(nd_coords)]
|
|
28
|
+
|
|
29
|
+
def convert_nd_coords_to_numpy_format(nd_coords):
|
|
30
|
+
"""
|
|
31
|
+
Converts N-dimensional coordinates to the numpy format (tuple).
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
nd_coords (numpy.ndarray): The N-dimensional coordinates.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
tuple: The N-dimensional coordinates in the numpy format.
|
|
38
|
+
|
|
39
|
+
Examples:
|
|
40
|
+
>>> nd_coords = np.array([[1, 2, 3], [4, 5, 6]])
|
|
41
|
+
>>> result = convert_nd_coords_to_numpy_format(nd_coords)
|
|
42
|
+
>>> print(result)
|
|
43
|
+
((1, 4), (2, 5), (3, 6))
|
|
44
|
+
|
|
45
|
+
"""
|
|
46
|
+
return tuple(nd_coords.T)
|
|
47
|
+
|
|
48
|
+
def set_coords_to_value(img, nd_coords, value):
|
|
49
|
+
"""
|
|
50
|
+
Sets the value at the specified N-dimensional coordinates in the image.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
img (numpy.ndarray): The input image.
|
|
54
|
+
nd_coords (numpy.ndarray): The N-dimensional coordinates.
|
|
55
|
+
value (int or float): The value to set.
|
|
56
|
+
|
|
57
|
+
Examples:
|
|
58
|
+
>>> img = np.zeros((3, 3))
|
|
59
|
+
>>> nd_coords = np.array([[0, 0], [1, 1]])
|
|
60
|
+
>>> value = 1
|
|
61
|
+
>>> set_coords_to_value(img, nd_coords, value)
|
|
62
|
+
>>> print(img)
|
|
63
|
+
[[1. 0. 0.]
|
|
64
|
+
[0. 1. 0.]
|
|
65
|
+
[0. 0. 0.]]
|
|
66
|
+
|
|
67
|
+
"""
|
|
68
|
+
img[convert_nd_coords_to_numpy_format(nd_coords)] = value
|
|
69
|
+
|
|
70
|
+
def convert_numpy_bbox_to_coord_pairs(bbox):
|
|
71
|
+
"""
|
|
72
|
+
Converts a linear bounding box to coordinate pairs.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
bbox (numpy.ndarray or list): The bounding box.
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
numpy.ndarray: The coordinate pairs.
|
|
79
|
+
|
|
80
|
+
Examples:
|
|
81
|
+
>>> bbox = [1, 2, 3, 4, 5, 6]
|
|
82
|
+
>>> result = convert_numpy_bbox_to_coord_pairs(bbox)
|
|
83
|
+
>>> print(result)
|
|
84
|
+
[[1 4]
|
|
85
|
+
[2 5]
|
|
86
|
+
[3 6]]
|
|
87
|
+
|
|
88
|
+
"""
|
|
89
|
+
if not isinstance(bbox, np.ndarray):
|
|
90
|
+
bbox = np.asarray(bbox)
|
|
91
|
+
return np.reshape(bbox, (2, int(bbox.size / 2))).T
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def get_image_bounds(original_image):
|
|
95
|
+
"""
|
|
96
|
+
Returns the coordinate bounds of an image.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
original_image (numpy.ndarray): The original image.
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
numpy.ndarray: The coordinate bounds.
|
|
103
|
+
|
|
104
|
+
Examples:
|
|
105
|
+
>>> original_image = np.zeros((5, 5))
|
|
106
|
+
>>> result = get_image_bounds(original_image)
|
|
107
|
+
>>> print(result)
|
|
108
|
+
[[0 5]
|
|
109
|
+
[0 5]]
|
|
110
|
+
|
|
111
|
+
"""
|
|
112
|
+
bounds = []
|
|
113
|
+
for dim in range(len(original_image.shape)):
|
|
114
|
+
bounds.append(0)
|
|
115
|
+
bounds.append(original_image.shape[dim])
|
|
116
|
+
|
|
117
|
+
bounds = np.asarray(bounds).reshape(-1, 2)
|
|
118
|
+
return bounds
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def filter_nan_rows(coords):
|
|
122
|
+
"""
|
|
123
|
+
Filters out rows containing NaN values from a coordinate array.
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
coords (numpy.ndarray): The coordinate array.
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
numpy.ndarray: The filtered coordinate array.
|
|
130
|
+
|
|
131
|
+
Examples:
|
|
132
|
+
>>> coords = np.array([[1, 2], [3, np.nan], [4, 5]])
|
|
133
|
+
>>> result = filter_nan_rows(coords)
|
|
134
|
+
>>> print(result)
|
|
135
|
+
[[1. 2.]
|
|
136
|
+
[4. 5.]]
|
|
137
|
+
|
|
138
|
+
"""
|
|
139
|
+
if coords.size == 0:
|
|
140
|
+
print('empty array --> returning array')
|
|
141
|
+
return coords
|
|
142
|
+
return coords[~np.isnan(coords).any(axis=1)]
|
|
143
|
+
|
|
144
|
+
def get_histogram_edges(min, max, increment):
|
|
145
|
+
"""
|
|
146
|
+
Returns the bin edges for a histogram.
|
|
147
|
+
|
|
148
|
+
Args:
|
|
149
|
+
min (int or float): The minimum value.
|
|
150
|
+
max (int or float): The maximum value.
|
|
151
|
+
increment (int or float): The increment between bin edges.
|
|
152
|
+
|
|
153
|
+
Returns:
|
|
154
|
+
numpy.ndarray: The bin edges.
|
|
155
|
+
|
|
156
|
+
Examples:
|
|
157
|
+
>>> min_val = 0
|
|
158
|
+
>>> max_val = 10
|
|
159
|
+
>>> increment = 2
|
|
160
|
+
>>> result = get_histogram_edges(min_val, max_val, increment)
|
|
161
|
+
>>> print(result)
|
|
162
|
+
[ 0 2 4 6 8 10]
|
|
163
|
+
|
|
164
|
+
"""
|
|
165
|
+
bin_edges = np.arange(min, max + 1, increment)
|
|
166
|
+
return bin_edges
|
|
167
|
+
|
|
168
|
+
def find_factors(arr):
|
|
169
|
+
"""
|
|
170
|
+
Returns the unique values in an array.
|
|
171
|
+
|
|
172
|
+
Args:
|
|
173
|
+
arr (array-like): The input array.
|
|
174
|
+
|
|
175
|
+
Returns:
|
|
176
|
+
numpy.ndarray: An array containing the unique values in the input array.
|
|
177
|
+
|
|
178
|
+
Examples:
|
|
179
|
+
>>> find_factors(['apple', 'banana', 'banana', 'cherry', 'cherry', 'durian'])
|
|
180
|
+
array(['apple', 'banana', 'cherry', 'durian'], dtype='<U6')
|
|
181
|
+
|
|
182
|
+
>>> find_factors(['apple', 'apple', 'apple', 'apple'])
|
|
183
|
+
array(['apple'], dtype='<U5')
|
|
184
|
+
|
|
185
|
+
>>> find_factors(['cat', 'dog', 'elephant'])
|
|
186
|
+
array(['cat', 'dog', 'elephant'], dtype='<U8')
|
|
187
|
+
|
|
188
|
+
"""
|
|
189
|
+
unique_vals = np.unique(arr)
|
|
190
|
+
return unique_vals
|
|
191
|
+
|
|
192
|
+
# def get_all_colors(arr):
|
|
193
|
+
# return np.unique(arr)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def create_image_with_lines(image_size, x_spacing, y_spacing):
|
|
197
|
+
"""
|
|
198
|
+
Create a black numpy image with lines every x_spacing pixels in the x direction
|
|
199
|
+
and every y_spacing pixels in the y direction.
|
|
200
|
+
|
|
201
|
+
Parameters:
|
|
202
|
+
image_size (tuple): The size of the image (width, height).
|
|
203
|
+
x_spacing (int): The spacing between vertical lines.
|
|
204
|
+
y_spacing (int): The spacing between horizontal lines.
|
|
205
|
+
|
|
206
|
+
Returns:
|
|
207
|
+
numpy.ndarray: The image.
|
|
208
|
+
"""
|
|
209
|
+
from skimage import draw, color
|
|
210
|
+
# Create a black numpy image
|
|
211
|
+
image = np.zeros(image_size, dtype=np.uint8)
|
|
212
|
+
|
|
213
|
+
# Draw vertical lines every x_spacing pixels
|
|
214
|
+
for x in range(0, image_size[0], x_spacing):
|
|
215
|
+
print(x, 0, x, image_size[1])
|
|
216
|
+
|
|
217
|
+
rr, cc = draw.line(x, 0, x, image_size[1]-1)
|
|
218
|
+
image[rr, cc] = 255
|
|
219
|
+
|
|
220
|
+
# Draw horizontal lines every y_spacing pixels
|
|
221
|
+
for y in range(0, image_size[1], y_spacing):
|
|
222
|
+
rr, cc = draw.line(0, y, image_size[0]-1, y)
|
|
223
|
+
image[rr, cc] = 255
|
|
224
|
+
|
|
225
|
+
return image
|
|
226
|
+
|
|
227
|
+
if __name__ == '__main__':
|
|
228
|
+
if True:
|
|
229
|
+
# Example usage
|
|
230
|
+
image_size = (800, 600) # Width, Height
|
|
231
|
+
x_spacing = 50
|
|
232
|
+
y_spacing = 100
|
|
233
|
+
image = create_image_with_lines(image_size, x_spacing, y_spacing) # this grid image can be used to debug image crop --> TODO
|
|
234
|
+
|
|
235
|
+
# Display the image
|
|
236
|
+
plt.imshow(image)
|
|
237
|
+
plt.show()
|
|
238
|
+
|
|
239
|
+
sys.exit(0)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
print(get_histogram_edges(0,100,25)) # increment of 25 between 0 and 100 -−> give all the pairs of bounds for an histogram --> [ 0 25 50 75 100]
|
|
243
|
+
print(get_histogram_edges(0,100,10)) # increment of 10 between 0 and 100 -−> give all the pairs of bounds for an histogram --> [ 0 10 20 30 40 50 60 70 80 90 100]
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
test = np.zeros(shape=(32,32))
|
|
248
|
+
coords = np.asarray([[0,0],[16,16],[20,20]])
|
|
249
|
+
set_coords_to_value(test, coords, 255) # --> same as test[coords[:,0],coords[:,1]] # and what is great is that infinite nb of dims are supported --> can write generic code for 2D and 3D --> really cool --> replace everywhere in my code
|
|
250
|
+
plt.imshow(test)
|
|
251
|
+
plt.show()
|
|
252
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
# Create a 3D array with 100 rows
|
|
4
|
+
arr = np.random.rand(100, 3)
|
|
5
|
+
|
|
6
|
+
# Create a boolean index of length 100 that has only 5 True values
|
|
7
|
+
bool_index = np.zeros(100, dtype=bool)
|
|
8
|
+
bool_index[:5] = True
|
|
9
|
+
np.random.shuffle(bool_index)
|
|
10
|
+
|
|
11
|
+
print(bool_index.shape)
|
|
12
|
+
# Filter the rows of the 3D array using the boolean index
|
|
13
|
+
filtered_arr = arr[bool_index]
|
|
14
|
+
|
|
15
|
+
print(filtered_arr.shape)
|
|
File without changes
|