Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Example notebooks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Masiliunas, Dainius
Example notebooks
Commits
d520dd7e
Commit
d520dd7e
authored
5 years ago
by
Dainius
Browse files
Options
Downloads
Patches
Plain Diff
Add an example of a fairly-efficient apply on multidimensional arrays
parent
7a423bb9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apply_on_raster_timeseries.ipynb
+245
-0
245 additions, 0 deletions
apply_on_raster_timeseries.ipynb
with
245 additions
and
0 deletions
apply_on_raster_timeseries.ipynb
0 → 100644
+
245
−
0
View file @
d520dd7e
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"a = array(1:27, dim=c(3,3,3)) # 3D array: x,y,time"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"aq = apply(a, c(1,2), quantile) # Also a 3D array, but for some reason quantile,y,x"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<ol class=list-inline>\n",
"\t<li>1</li>\n",
"\t<li>4</li>\n",
"\t<li>7</li>\n",
"\t<li>2</li>\n",
"\t<li>5</li>\n",
"\t<li>8</li>\n",
"\t<li>3</li>\n",
"\t<li>6</li>\n",
"\t<li>9</li>\n",
"\t<li>5.5</li>\n",
"\t<li>8.5</li>\n",
"\t<li>11.5</li>\n",
"\t<li>6.5</li>\n",
"\t<li>9.5</li>\n",
"\t<li>12.5</li>\n",
"\t<li>7.5</li>\n",
"\t<li>10.5</li>\n",
"\t<li>13.5</li>\n",
"\t<li>10</li>\n",
"\t<li>13</li>\n",
"\t<li>16</li>\n",
"\t<li>11</li>\n",
"\t<li>14</li>\n",
"\t<li>17</li>\n",
"\t<li>12</li>\n",
"\t<li>15</li>\n",
"\t<li>18</li>\n",
"\t<li>14.5</li>\n",
"\t<li>17.5</li>\n",
"\t<li>20.5</li>\n",
"\t<li>15.5</li>\n",
"\t<li>18.5</li>\n",
"\t<li>21.5</li>\n",
"\t<li>16.5</li>\n",
"\t<li>19.5</li>\n",
"\t<li>22.5</li>\n",
"\t<li>19</li>\n",
"\t<li>22</li>\n",
"\t<li>25</li>\n",
"\t<li>20</li>\n",
"\t<li>23</li>\n",
"\t<li>26</li>\n",
"\t<li>21</li>\n",
"\t<li>24</li>\n",
"\t<li>27</li>\n",
"</ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 1\n",
"\\item 4\n",
"\\item 7\n",
"\\item 2\n",
"\\item 5\n",
"\\item 8\n",
"\\item 3\n",
"\\item 6\n",
"\\item 9\n",
"\\item 5.5\n",
"\\item 8.5\n",
"\\item 11.5\n",
"\\item 6.5\n",
"\\item 9.5\n",
"\\item 12.5\n",
"\\item 7.5\n",
"\\item 10.5\n",
"\\item 13.5\n",
"\\item 10\n",
"\\item 13\n",
"\\item 16\n",
"\\item 11\n",
"\\item 14\n",
"\\item 17\n",
"\\item 12\n",
"\\item 15\n",
"\\item 18\n",
"\\item 14.5\n",
"\\item 17.5\n",
"\\item 20.5\n",
"\\item 15.5\n",
"\\item 18.5\n",
"\\item 21.5\n",
"\\item 16.5\n",
"\\item 19.5\n",
"\\item 22.5\n",
"\\item 19\n",
"\\item 22\n",
"\\item 25\n",
"\\item 20\n",
"\\item 23\n",
"\\item 26\n",
"\\item 21\n",
"\\item 24\n",
"\\item 27\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 1\n",
"2. 4\n",
"3. 7\n",
"4. 2\n",
"5. 5\n",
"6. 8\n",
"7. 3\n",
"8. 6\n",
"9. 9\n",
"10. 5.5\n",
"11. 8.5\n",
"12. 11.5\n",
"13. 6.5\n",
"14. 9.5\n",
"15. 12.5\n",
"16. 7.5\n",
"17. 10.5\n",
"18. 13.5\n",
"19. 10\n",
"20. 13\n",
"21. 16\n",
"22. 11\n",
"23. 14\n",
"24. 17\n",
"25. 12\n",
"26. 15\n",
"27. 18\n",
"28. 14.5\n",
"29. 17.5\n",
"30. 20.5\n",
"31. 15.5\n",
"32. 18.5\n",
"33. 21.5\n",
"34. 16.5\n",
"35. 19.5\n",
"36. 22.5\n",
"37. 19\n",
"38. 22\n",
"39. 25\n",
"40. 20\n",
"41. 23\n",
"42. 26\n",
"43. 21\n",
"44. 24\n",
"45. 27\n",
"\n",
"\n"
],
"text/plain": [
", , 0%\n",
"\n",
" [,1] [,2] [,3]\n",
"[1,] 1 2 3\n",
"[2,] 4 5 6\n",
"[3,] 7 8 9\n",
"\n",
", , 25%\n",
"\n",
" [,1] [,2] [,3]\n",
"[1,] 5.5 6.5 7.5\n",
"[2,] 8.5 9.5 10.5\n",
"[3,] 11.5 12.5 13.5\n",
"\n",
", , 50%\n",
"\n",
" [,1] [,2] [,3]\n",
"[1,] 10 11 12\n",
"[2,] 13 14 15\n",
"[3,] 16 17 18\n",
"\n",
", , 75%\n",
"\n",
" [,1] [,2] [,3]\n",
"[1,] 14.5 15.5 16.5\n",
"[2,] 17.5 18.5 19.5\n",
"[3,] 20.5 21.5 22.5\n",
"\n",
", , 100%\n",
"\n",
" [,1] [,2] [,3]\n",
"[1,] 19 20 21\n",
"[2,] 22 23 24\n",
"[3,] 25 26 27\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"aperm(aq) # Like t, but for arrays"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "R",
"language": "R",
"name": "ir"
},
"language_info": {
"codemirror_mode": "r",
"file_extension": ".r",
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "3.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% Cell type:code id: tags:
```
R
a
=
array
(
1
:
27
,
dim
=
c
(
3
,
3
,
3
))
# 3D array: x,y,time
```
%% Cell type:code id: tags:
```
R
aq
=
apply
(
a
,
c
(
1
,
2
),
quantile
)
# Also a 3D array, but for some reason quantile,y,x
```
%% Cell type:code id: tags:
```
R
aperm
(
aq
)
# Like t, but for arrays
```
%% Output
1. 1
2. 4
3. 7
4. 2
5. 5
6. 8
7. 3
8. 6
9. 9
10. 5.5
11. 8.5
12. 11.5
13. 6.5
14. 9.5
15. 12.5
16. 7.5
17. 10.5
18. 13.5
19. 10
20. 13
21. 16
22. 11
23. 14
24. 17
25. 12
26. 15
27. 18
28. 14.5
29. 17.5
30. 20.5
31. 15.5
32. 18.5
33. 21.5
34. 16.5
35. 19.5
36. 22.5
37. 19
38. 22
39. 25
40. 20
41. 23
42. 26
43. 21
44. 24
45. 27
\begin{enumerate*}
\item 1
\item 4
\item 7
\item 2
\item 5
\item 8
\item 3
\item 6
\item 9
\item 5.5
\item 8.5
\item 11.5
\item 6.5
\item 9.5
\item 12.5
\item 7.5
\item 10.5
\item 13.5
\item 10
\item 13
\item 16
\item 11
\item 14
\item 17
\item 12
\item 15
\item 18
\item 14.5
\item 17.5
\item 20.5
\item 15.5
\item 18.5
\item 21.5
\item 16.5
\item 19.5
\item 22.5
\item 19
\item 22
\item 25
\item 20
\item 23
\item 26
\item 21
\item 24
\item 27
\end{enumerate*}
%% Cell type:code id: tags:
```
R
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment