-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdivide.py
executable file
·102 lines (96 loc) · 4.33 KB
/
divide.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import numpy as np
def divide_array_into_chunks(array, n):
"""
Divide a NumPy array into n approximately equal chunks.
Parameters:
array (numpy.ndarray): The input array to be divided.
n (int): The number of chunks to divide the array into.
Returns:
list of numpy.ndarray: A list containing the divided chunks of the array.
"""
chunk_size = len(array) // n
remainder = len(array) % n
chunks = []
start = 0
for i in range(n):
end = start + chunk_size + (1 if i < remainder else 0)
chunks.append(array[start:end])
start = end
return chunks
# Example usage:
data = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
X = np.array([[9.65], [8.87], [8.], [8.67], [8.21], [9.34], [8.2], [7.9], [8.], [8.6], [8.4],
[9.], [9.1], [8.], [8.2], [8.3], [8.7], [
8.], [8.8], [8.5], [7.9], [8.4],
[9.5], [9.7], [9.8], [9.6], [8.8], [7.5], [
7.2], [7.3], [8.1], [8.3], [9.4],
[9.6], [9.8], [9.2], [8.4], [7.8], [
7.5], [7.7], [8.], [8.2], [8.5], [9.1],
[9.4], [9.1], [9.3], [9.7], [8.85], [
8.4], [8.3], [7.9], [8.], [8.1], [8.],
[7.7], [7.4], [7.6], [6.8], [8.3], [8.1], [
8.2], [8.2], [8.5], [8.7], [8.92],
[9.02], [8.64], [9.22], [9.16], [9.64], [
9.76], [9.45], [9.04], [8.9], [8.56], [8.72],
[8.22], [7.54], [7.36], [8.02], [9.5], [9.22], [
9.36], [9.45], [8.66], [8.42], [8.28],
[8.14], [8.76], [7.92], [7.66], [8.03], [
7.88], [7.66], [7.84], [8.], [8.96], [9.24],
[8.88], [8.46], [8.12], [8.25], [8.47], [9.05], [
8.78], [9.18], [9.46], [9.38], [8.64],
[8.48], [8.68], [8.34], [8.56], [8.45], [9.04], [
8.62], [7.46], [7.28], [8.84], [9.56],
[9.48], [8.36], [8.22], [8.47], [8.66], [
9.32], [8.71], [9.1], [9.35], [9.76], [8.65],
[8.56], [8.78], [9.28], [8.77], [8.45], [8.16], [
9.08], [9.12], [9.15], [9.36], [9.44],
[9.92], [8.96], [8.64], [8.48], [9.11], [9.8], [
8.26], [9.43], [9.28], [9.06], [8.75],
[8.89], [8.69], [8.34], [8.26], [8.14], [
7.9], [7.86], [7.46], [8.5], [8.56], [9.01],
[8.97], [8.33], [8.27], [7.8], [7.98], [8.04], [
9.07], [9.13], [9.23], [8.97], [8.87],
[9.16], [9.04], [8.12], [8.27], [8.16], [
8.42], [7.88], [8.8], [8.32], [9.11], [8.68],
[9.44], [9.36], [9.08], [9.16], [8.98], [8.94], [
9.53], [8.76], [8.52], [8.26], [8.33],
[8.43], [8.69], [8.54], [8.46], [9.91], [9.87], [8.54], [
7.65], [7.89], [8.02], [8.16], [8.12], [9.06], [9.14],
[9.66], [9.78], [9.42], [9.36], [9.26], [9.13], [
8.97], [8.42], [8.75], [8.56], [8.79],
[8.45], [8.23], [8.03], [8.45], [8.53], [8.67], [
9.01], [8.65], [8.33], [8.27], [8.07],
[9.31], [9.23], [9.17], [9.19], [8.37], [7.89], [
7.68], [8.15], [8.76], [9.04], [8.56],
[9.02], [8.73], [8.48], [8.87], [8.83], [
8.57], [9.], [8.54], [9.68], [9.12], [8.37],
[8.56], [8.64], [8.76], [9.34], [9.13], [8.09], [
8.36], [8.79], [8.76], [8.68], [8.45],
[8.17], [9.14], [8.34], [8.22], [7.86], [7.64], [
8.01], [7.95], [8.96], [9.45], [8.62],
[8.49], [8.73], [8.64], [9.11], [8.79], [8.9], [
9.66], [9.26], [9.19], [9.08], [9.02],
[9.], [7.65], [7.87], [7.97], [8.18], [8.32], [
8.57], [8.67], [9.11], [9.24], [8.65],
[8.], [8.76], [8.45], [8.55], [8.43], [
8.8], [9.1], [9.], [8.53], [8.6], [8.74],
[9.18], [9.], [8.04], [8.13], [8.07], [7.86], [
8.01], [8.8], [8.69], [8.5], [8.44],
[8.27], [8.18], [8.33], [9.14], [8.02], [7.86], [
8.77], [7.89], [8.66], [8.12], [8.21],
[8.54], [8.65], [9.11], [8.79], [9.47], [8.74], [
8.66], [8.46], [8.76], [8.24], [8.13],
[7.34], [7.43], [7.64], [7.34], [7.25], [8.04], [
8.27], [8.67], [8.06], [8.17], [7.67],
[8.12], [8.77], [7.89], [7.64], [8.44], [
8.64], [9.54], [9.23], [8.36], [8.9], [9.17],
[8.34], [7.46], [7.88], [8.03], [8.24], [9.22], [
9.62], [8.54], [7.65], [7.66], [7.43],
[7.56], [7.65], [8.43], [8.84], [8.67], [
9.15], [8.26], [9.74], [9.82], [7.96], [8.1],
[7.8], [8.44], [8.24], [8.65], [9.12], [8.76], [
9.23], [9.04], [9.11], [9.45], [8.78],
[9.66]])
num_chunks = 5
chunks = divide_array_into_chunks(X, num_chunks)
print(chunks)