回答編集履歴
2
docstringを追加
test
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
+
Pythonで書かれた部分は、簡単に確認が可能です。
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
動的リンクライブラリの形で提供されているC言語やアセンブラで書かれた部分は、別途ソースコードをダウンロードすれば確認できます。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
Pythonで書かれた部分の確認は以下のように行います。
|
14
|
+
|
15
|
+
|
16
|
+
|
5
17
|
```python
|
6
18
|
|
7
19
|
>>> print(numpy)
|
@@ -16,6 +28,180 @@
|
|
16
28
|
|
17
29
|
また、Pythonで書かれた関数などはinspectモジュールをimportすれば、inspect.getsource関数を使ってソースを表示することが出来ます。
|
18
30
|
|
19
|
-
|
31
|
+
少々長いですが以下のような感じです。
|
32
|
+
|
33
|
+
|
34
|
+
|
20
|
-
|
35
|
+
```python
|
36
|
+
|
37
|
+
>>> print(inspect.getsource(numpy.split))
|
38
|
+
|
39
|
+
@array_function_dispatch(_split_dispatcher)
|
40
|
+
|
41
|
+
def split(ary, indices_or_sections, axis=0):
|
42
|
+
|
43
|
+
"""
|
44
|
+
|
45
|
+
Split an array into multiple sub-arrays as views into `ary`.
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
Parameters
|
50
|
+
|
51
|
+
----------
|
52
|
+
|
53
|
+
ary : ndarray
|
54
|
+
|
55
|
+
Array to be divided into sub-arrays.
|
56
|
+
|
57
|
+
indices_or_sections : int or 1-D array
|
58
|
+
|
59
|
+
If `indices_or_sections` is an integer, N, the array will be divided
|
60
|
+
|
61
|
+
into N equal arrays along `axis`. If such a split is not possible,
|
62
|
+
|
63
|
+
an error is raised.
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
If `indices_or_sections` is a 1-D array of sorted integers, the entries
|
68
|
+
|
69
|
+
indicate where along `axis` the array is split. For example,
|
70
|
+
|
71
|
+
``[2, 3]`` would, for ``axis=0``, result in
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
- ary[:2]
|
76
|
+
|
77
|
+
- ary[2:3]
|
78
|
+
|
79
|
+
- ary[3:]
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
If an index exceeds the dimension of the array along `axis`,
|
84
|
+
|
85
|
+
an empty sub-array is returned correspondingly.
|
86
|
+
|
87
|
+
axis : int, optional
|
88
|
+
|
89
|
+
The axis along which to split, default is 0.
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
Returns
|
94
|
+
|
95
|
+
-------
|
96
|
+
|
97
|
+
sub-arrays : list of ndarrays
|
98
|
+
|
99
|
+
A list of sub-arrays as views into `ary`.
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
Raises
|
104
|
+
|
105
|
+
------
|
106
|
+
|
107
|
+
ValueError
|
108
|
+
|
109
|
+
If `indices_or_sections` is given as an integer, but
|
110
|
+
|
111
|
+
a split does not result in equal division.
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
See Also
|
116
|
+
|
117
|
+
--------
|
118
|
+
|
119
|
+
array_split : Split an array into multiple sub-arrays of equal or
|
120
|
+
|
121
|
+
near-equal size. Does not raise an exception if
|
122
|
+
|
123
|
+
an equal division cannot be made.
|
124
|
+
|
125
|
+
hsplit : Split array into multiple sub-arrays horizontally (column-wise).
|
126
|
+
|
127
|
+
vsplit : Split array into multiple sub-arrays vertically (row wise).
|
128
|
+
|
129
|
+
dsplit : Split array into multiple sub-arrays along the 3rd axis (depth).
|
130
|
+
|
21
|
-
|
131
|
+
concatenate : Join a sequence of arrays along an existing axis.
|
132
|
+
|
133
|
+
stack : Join a sequence of arrays along a new axis.
|
134
|
+
|
135
|
+
hstack : Stack arrays in sequence horizontally (column wise).
|
136
|
+
|
137
|
+
vstack : Stack arrays in sequence vertically (row wise).
|
138
|
+
|
139
|
+
dstack : Stack arrays in sequence depth wise (along third dimension).
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
Examples
|
144
|
+
|
145
|
+
--------
|
146
|
+
|
147
|
+
>>> x = np.arange(9.0)
|
148
|
+
|
149
|
+
>>> np.split(x, 3)
|
150
|
+
|
151
|
+
[array([0., 1., 2.]), array([3., 4., 5.]), array([6., 7., 8.])]
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
>>> x = np.arange(8.0)
|
156
|
+
|
157
|
+
>>> np.split(x, [3, 5, 6, 10])
|
158
|
+
|
159
|
+
[array([0., 1., 2.]),
|
160
|
+
|
161
|
+
array([3., 4.]),
|
162
|
+
|
163
|
+
array([5.]),
|
164
|
+
|
165
|
+
array([6., 7.]),
|
166
|
+
|
167
|
+
array([], dtype=float64)]
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
"""
|
172
|
+
|
173
|
+
try:
|
174
|
+
|
175
|
+
len(indices_or_sections)
|
176
|
+
|
177
|
+
except TypeError:
|
178
|
+
|
179
|
+
sections = indices_or_sections
|
180
|
+
|
181
|
+
N = ary.shape[axis]
|
182
|
+
|
183
|
+
if N % sections:
|
184
|
+
|
185
|
+
raise ValueError(
|
186
|
+
|
187
|
+
'array split does not result in an equal division')
|
188
|
+
|
189
|
+
return array_split(ary, indices_or_sections, axis)
|
190
|
+
|
191
|
+
```
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
また、上記の関数のdocstringの部分は以下を実行すれば表示することができます。
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
```python
|
200
|
+
|
201
|
+
print(numpy.split.__doc__)
|
202
|
+
|
203
|
+
または
|
204
|
+
|
205
|
+
help(numpy.split)
|
206
|
+
|
207
|
+
```
|
1
inspect.getsourceを追加
test
CHANGED
@@ -14,4 +14,8 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
+
また、Pythonで書かれた関数などはinspectモジュールをimportすれば、inspect.getsource関数を使ってソースを表示することが出来ます。
|
18
|
+
|
19
|
+
|
20
|
+
|
17
21
|
動的リンクライブラリの形で提供されているC言語やアセンブラで書かれた部分は、別途ソースコードをダウンロードすれば確認できます。
|