How can I find maximum along multiple axes of a multidimensional numpy array?
up vote
0
down vote
favorite
I have a numpy array of these dimensions
data.shape
(categories, models, types, events, days) -> (10, 11, 50, 100, 14)
Now, I want to find the maximum of the 14 days for all events for each of the 11 models. But I am not sure how to do it in the numpy
way. I am not sure if this is correct.
modelmax =
nmodels = 11
for modelcount in range(nmodels):
modelmax.append(np.max(data[0][modelcount][:], axis=2))
As an example, for the 100 events:
np.max(data, axis=4)[0][0][0])
[ 3.9264417 3.3029506 3.0707457 3.6646023 1.7508441 3.1634364
6.195052 1.5353022 1.8033538 1.4508389 1.3882699 2.0849068
3.654939 6.6364765 3.92829 6.6467876 1.5442419 4.639682
9.361191 5.261462 1.7438816 5.6970205 2.4356377 1.6073244
2.6177561 6.886767 3.890399 2.8880894 1.9826577 1.0888597
4.3763924 3.8597727 1.790302 1.0277777 6.270729 9.311213
2.318774 2.9298437 1.139397 0.9598383 3.0489902 1.6736581
1.3983868 2.0979824 4.169757 1.0739225 1.5311266 1.4676268
1.726325 1.8057758 2.226462 2.6197987 4.49518 2.3042605
5.7164993 1.182242 1.5107205 2.2920077 2.205539 1.4702082
2.154468 2.0641963 4.9628353 1.9987459 2.1360166 1.7073958
1.943267 7.5767093 1.3124634 2.2648168 1.1504744 3.210688
2.6720855 2.998225 4.365262 3.5410352 10.765423 4.6292825
3.1789696 0.92157686 1.663245 1.5835482 3.1070056 1.6918416
8.086268 3.7994847 2.4314868 1.6471033 1.1688241 1.7820593
3.3509188 1.3092748 3.7915008 1.018912 3.2404447 1.596657
2.0869658 2.6753283 2.1096318 8.786542 ]
I have also tried
np.max(dryflow[0][:], axis=3)
But these multidimensional indices are leaving me confused.
python numpy
|
show 2 more comments
up vote
0
down vote
favorite
I have a numpy array of these dimensions
data.shape
(categories, models, types, events, days) -> (10, 11, 50, 100, 14)
Now, I want to find the maximum of the 14 days for all events for each of the 11 models. But I am not sure how to do it in the numpy
way. I am not sure if this is correct.
modelmax =
nmodels = 11
for modelcount in range(nmodels):
modelmax.append(np.max(data[0][modelcount][:], axis=2))
As an example, for the 100 events:
np.max(data, axis=4)[0][0][0])
[ 3.9264417 3.3029506 3.0707457 3.6646023 1.7508441 3.1634364
6.195052 1.5353022 1.8033538 1.4508389 1.3882699 2.0849068
3.654939 6.6364765 3.92829 6.6467876 1.5442419 4.639682
9.361191 5.261462 1.7438816 5.6970205 2.4356377 1.6073244
2.6177561 6.886767 3.890399 2.8880894 1.9826577 1.0888597
4.3763924 3.8597727 1.790302 1.0277777 6.270729 9.311213
2.318774 2.9298437 1.139397 0.9598383 3.0489902 1.6736581
1.3983868 2.0979824 4.169757 1.0739225 1.5311266 1.4676268
1.726325 1.8057758 2.226462 2.6197987 4.49518 2.3042605
5.7164993 1.182242 1.5107205 2.2920077 2.205539 1.4702082
2.154468 2.0641963 4.9628353 1.9987459 2.1360166 1.7073958
1.943267 7.5767093 1.3124634 2.2648168 1.1504744 3.210688
2.6720855 2.998225 4.365262 3.5410352 10.765423 4.6292825
3.1789696 0.92157686 1.663245 1.5835482 3.1070056 1.6918416
8.086268 3.7994847 2.4314868 1.6471033 1.1688241 1.7820593
3.3509188 1.3092748 3.7915008 1.018912 3.2404447 1.596657
2.0869658 2.6753283 2.1096318 8.786542 ]
I have also tried
np.max(dryflow[0][:], axis=3)
But these multidimensional indices are leaving me confused.
python numpy
And what aboutcategories
andtypes
?
– Chiel
Nov 7 at 22:12
@Chiel I am trying to reduce the complexity of the problem for understanding purposes. But if I could have the daily maximums for category, model, type and event, that would be swell....I am just very confused regarding the multi-dims, and I am probably not relaying what I don't understand...
– maximusdooku
Nov 7 at 22:16
Eventually, I will take thelog
of the 14 day maximums and find the overall maximum and minimum for every type...Hope it explains a bit..
– maximusdooku
Nov 7 at 22:18
Innumpy
it is better to use[0,0,0,0]
style of indexing rather than[0][0][0][0]
. Sometimes they produce the same thing, but sometimes the differences give problems. Also with arrays[:]
does nothing for you.
– hpaulj
Nov 7 at 22:20
@hpaulj Thanks! I didn't know there was any difference. BTW, can you expand a little bit on[:]
doing nothing..
– maximusdooku
Nov 7 at 22:23
|
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a numpy array of these dimensions
data.shape
(categories, models, types, events, days) -> (10, 11, 50, 100, 14)
Now, I want to find the maximum of the 14 days for all events for each of the 11 models. But I am not sure how to do it in the numpy
way. I am not sure if this is correct.
modelmax =
nmodels = 11
for modelcount in range(nmodels):
modelmax.append(np.max(data[0][modelcount][:], axis=2))
As an example, for the 100 events:
np.max(data, axis=4)[0][0][0])
[ 3.9264417 3.3029506 3.0707457 3.6646023 1.7508441 3.1634364
6.195052 1.5353022 1.8033538 1.4508389 1.3882699 2.0849068
3.654939 6.6364765 3.92829 6.6467876 1.5442419 4.639682
9.361191 5.261462 1.7438816 5.6970205 2.4356377 1.6073244
2.6177561 6.886767 3.890399 2.8880894 1.9826577 1.0888597
4.3763924 3.8597727 1.790302 1.0277777 6.270729 9.311213
2.318774 2.9298437 1.139397 0.9598383 3.0489902 1.6736581
1.3983868 2.0979824 4.169757 1.0739225 1.5311266 1.4676268
1.726325 1.8057758 2.226462 2.6197987 4.49518 2.3042605
5.7164993 1.182242 1.5107205 2.2920077 2.205539 1.4702082
2.154468 2.0641963 4.9628353 1.9987459 2.1360166 1.7073958
1.943267 7.5767093 1.3124634 2.2648168 1.1504744 3.210688
2.6720855 2.998225 4.365262 3.5410352 10.765423 4.6292825
3.1789696 0.92157686 1.663245 1.5835482 3.1070056 1.6918416
8.086268 3.7994847 2.4314868 1.6471033 1.1688241 1.7820593
3.3509188 1.3092748 3.7915008 1.018912 3.2404447 1.596657
2.0869658 2.6753283 2.1096318 8.786542 ]
I have also tried
np.max(dryflow[0][:], axis=3)
But these multidimensional indices are leaving me confused.
python numpy
I have a numpy array of these dimensions
data.shape
(categories, models, types, events, days) -> (10, 11, 50, 100, 14)
Now, I want to find the maximum of the 14 days for all events for each of the 11 models. But I am not sure how to do it in the numpy
way. I am not sure if this is correct.
modelmax =
nmodels = 11
for modelcount in range(nmodels):
modelmax.append(np.max(data[0][modelcount][:], axis=2))
As an example, for the 100 events:
np.max(data, axis=4)[0][0][0])
[ 3.9264417 3.3029506 3.0707457 3.6646023 1.7508441 3.1634364
6.195052 1.5353022 1.8033538 1.4508389 1.3882699 2.0849068
3.654939 6.6364765 3.92829 6.6467876 1.5442419 4.639682
9.361191 5.261462 1.7438816 5.6970205 2.4356377 1.6073244
2.6177561 6.886767 3.890399 2.8880894 1.9826577 1.0888597
4.3763924 3.8597727 1.790302 1.0277777 6.270729 9.311213
2.318774 2.9298437 1.139397 0.9598383 3.0489902 1.6736581
1.3983868 2.0979824 4.169757 1.0739225 1.5311266 1.4676268
1.726325 1.8057758 2.226462 2.6197987 4.49518 2.3042605
5.7164993 1.182242 1.5107205 2.2920077 2.205539 1.4702082
2.154468 2.0641963 4.9628353 1.9987459 2.1360166 1.7073958
1.943267 7.5767093 1.3124634 2.2648168 1.1504744 3.210688
2.6720855 2.998225 4.365262 3.5410352 10.765423 4.6292825
3.1789696 0.92157686 1.663245 1.5835482 3.1070056 1.6918416
8.086268 3.7994847 2.4314868 1.6471033 1.1688241 1.7820593
3.3509188 1.3092748 3.7915008 1.018912 3.2404447 1.596657
2.0869658 2.6753283 2.1096318 8.786542 ]
I have also tried
np.max(dryflow[0][:], axis=3)
But these multidimensional indices are leaving me confused.
python numpy
python numpy
edited Nov 7 at 22:09
asked Nov 7 at 22:01
maximusdooku
1,39021343
1,39021343
And what aboutcategories
andtypes
?
– Chiel
Nov 7 at 22:12
@Chiel I am trying to reduce the complexity of the problem for understanding purposes. But if I could have the daily maximums for category, model, type and event, that would be swell....I am just very confused regarding the multi-dims, and I am probably not relaying what I don't understand...
– maximusdooku
Nov 7 at 22:16
Eventually, I will take thelog
of the 14 day maximums and find the overall maximum and minimum for every type...Hope it explains a bit..
– maximusdooku
Nov 7 at 22:18
Innumpy
it is better to use[0,0,0,0]
style of indexing rather than[0][0][0][0]
. Sometimes they produce the same thing, but sometimes the differences give problems. Also with arrays[:]
does nothing for you.
– hpaulj
Nov 7 at 22:20
@hpaulj Thanks! I didn't know there was any difference. BTW, can you expand a little bit on[:]
doing nothing..
– maximusdooku
Nov 7 at 22:23
|
show 2 more comments
And what aboutcategories
andtypes
?
– Chiel
Nov 7 at 22:12
@Chiel I am trying to reduce the complexity of the problem for understanding purposes. But if I could have the daily maximums for category, model, type and event, that would be swell....I am just very confused regarding the multi-dims, and I am probably not relaying what I don't understand...
– maximusdooku
Nov 7 at 22:16
Eventually, I will take thelog
of the 14 day maximums and find the overall maximum and minimum for every type...Hope it explains a bit..
– maximusdooku
Nov 7 at 22:18
Innumpy
it is better to use[0,0,0,0]
style of indexing rather than[0][0][0][0]
. Sometimes they produce the same thing, but sometimes the differences give problems. Also with arrays[:]
does nothing for you.
– hpaulj
Nov 7 at 22:20
@hpaulj Thanks! I didn't know there was any difference. BTW, can you expand a little bit on[:]
doing nothing..
– maximusdooku
Nov 7 at 22:23
And what about
categories
and types
?– Chiel
Nov 7 at 22:12
And what about
categories
and types
?– Chiel
Nov 7 at 22:12
@Chiel I am trying to reduce the complexity of the problem for understanding purposes. But if I could have the daily maximums for category, model, type and event, that would be swell....I am just very confused regarding the multi-dims, and I am probably not relaying what I don't understand...
– maximusdooku
Nov 7 at 22:16
@Chiel I am trying to reduce the complexity of the problem for understanding purposes. But if I could have the daily maximums for category, model, type and event, that would be swell....I am just very confused regarding the multi-dims, and I am probably not relaying what I don't understand...
– maximusdooku
Nov 7 at 22:16
Eventually, I will take the
log
of the 14 day maximums and find the overall maximum and minimum for every type...Hope it explains a bit..– maximusdooku
Nov 7 at 22:18
Eventually, I will take the
log
of the 14 day maximums and find the overall maximum and minimum for every type...Hope it explains a bit..– maximusdooku
Nov 7 at 22:18
In
numpy
it is better to use [0,0,0,0]
style of indexing rather than [0][0][0][0]
. Sometimes they produce the same thing, but sometimes the differences give problems. Also with arrays [:]
does nothing for you.– hpaulj
Nov 7 at 22:20
In
numpy
it is better to use [0,0,0,0]
style of indexing rather than [0][0][0][0]
. Sometimes they produce the same thing, but sometimes the differences give problems. Also with arrays [:]
does nothing for you.– hpaulj
Nov 7 at 22:20
@hpaulj Thanks! I didn't know there was any difference. BTW, can you expand a little bit on
[:]
doing nothing..– maximusdooku
Nov 7 at 22:23
@hpaulj Thanks! I didn't know there was any difference. BTW, can you expand a little bit on
[:]
doing nothing..– maximusdooku
Nov 7 at 22:23
|
show 2 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53198520%2fhow-can-i-find-maximum-along-multiple-axes-of-a-multidimensional-numpy-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
And what about
categories
andtypes
?– Chiel
Nov 7 at 22:12
@Chiel I am trying to reduce the complexity of the problem for understanding purposes. But if I could have the daily maximums for category, model, type and event, that would be swell....I am just very confused regarding the multi-dims, and I am probably not relaying what I don't understand...
– maximusdooku
Nov 7 at 22:16
Eventually, I will take the
log
of the 14 day maximums and find the overall maximum and minimum for every type...Hope it explains a bit..– maximusdooku
Nov 7 at 22:18
In
numpy
it is better to use[0,0,0,0]
style of indexing rather than[0][0][0][0]
. Sometimes they produce the same thing, but sometimes the differences give problems. Also with arrays[:]
does nothing for you.– hpaulj
Nov 7 at 22:20
@hpaulj Thanks! I didn't know there was any difference. BTW, can you expand a little bit on
[:]
doing nothing..– maximusdooku
Nov 7 at 22:23