Index a 3D array with 2D array numpyPython: Access saved points from 2d array in 3d numpy arrayCreate ArrayList from arrayFinding the index of an item given a list containing it in PythonHow do I check if an array includes an object in JavaScript?How to append something to an array?Accessing the index in 'for' loops?How to insert an item into an array at a specific index (JavaScript)?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
Circuit Analysis: Obtaining Close Loop OP - AMP Transfer function
Quoting Keynes in a lecture
What is the highest possible scrabble score for placing a single tile
What does Apple's new App Store requirement mean
When were female captains banned from Starfleet?
A Trivial Diagnosis
Has the laser at Magurele, Romania reached a tenth of the Sun's power?
Are Captain Marvel's powers affected by Thanos breaking the Tesseract and claiming the stone?
Is there a RAID 0 Equivalent for RAM?
Which was the first story featuring espers?
How much of a Devil Fruit must be consumed to gain the power?
Which Article Helped Get Rid of Technobabble in RPGs?
Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?
"It doesn't matter" or "it won't matter"?
Non-trope happy ending?
Is my low blitz game drawing rate at www.chess.com an indicator that I am weak in chess?
Is it necessary to use pronouns with the verb "essere"?
Can you use Vicious Mockery to win an argument or gain favours?
Why is the "ls" command showing permissions of files in a FAT32 partition?
What features enable the Su-25 Frogfoot to operate with such a wide variety of fuels?
How can I write humor as character trait?
C++ check if statement can be evaluated constexpr
How could a planet have erratic days?
What kind of floor tile is this?
Index a 3D array with 2D array numpy
Python: Access saved points from 2d array in 3d numpy arrayCreate ArrayList from arrayFinding the index of an item given a list containing it in PythonHow do I check if an array includes an object in JavaScript?How to append something to an array?Accessing the index in 'for' loops?How to insert an item into an array at a specific index (JavaScript)?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
I'm trying to manipulate an index and source array such that:
result[ i ][ j ][ k ] = source[ i ][ indices[ i ][ j ][ k ] ]
I know how to do this with for loops but I'm using giant arrays and I'd like to use something more time efficient. I've tried to use numpy's advanced indexing but I don't really understand it.
Example functionality:
source = [[0.0 0.1 0.2 0.3]
[1.0 1.1 1.2 1.3]
[2.0 2.1 2.2 2.3]]
indices = [[[3 1 0 1]
[3 0 0 3]]
[[0 1 0 2]
[3 2 1 1]]
[[1 1 0 1]
[0 1 2 2]]]
# result[i][j][k] = source[i][indices[i][j][k]]
result = [[[0.3 0.1 0.0 0.1]
[0.3 0.0 0.0 0.3]]
[[1.0 1.1 1.0 1.2]
[1.3 1.2 1.1 1.1]]
[[2.1 2.1 2.0 2.1]
[2.0 2.1 2.2 2.2]]]
python arrays numpy
add a comment |
I'm trying to manipulate an index and source array such that:
result[ i ][ j ][ k ] = source[ i ][ indices[ i ][ j ][ k ] ]
I know how to do this with for loops but I'm using giant arrays and I'd like to use something more time efficient. I've tried to use numpy's advanced indexing but I don't really understand it.
Example functionality:
source = [[0.0 0.1 0.2 0.3]
[1.0 1.1 1.2 1.3]
[2.0 2.1 2.2 2.3]]
indices = [[[3 1 0 1]
[3 0 0 3]]
[[0 1 0 2]
[3 2 1 1]]
[[1 1 0 1]
[0 1 2 2]]]
# result[i][j][k] = source[i][indices[i][j][k]]
result = [[[0.3 0.1 0.0 0.1]
[0.3 0.0 0.0 0.3]]
[[1.0 1.1 1.0 1.2]
[1.3 1.2 1.1 1.1]]
[[2.1 2.1 2.0 2.1]
[2.0 2.1 2.2 2.2]]]
python arrays numpy
You needidx0 = np.r_['0,3,0', :3]. which is the same asnp.arange(3).reshape(3,1,1)Thenresult = source[idx0, indices]
– Paul Panzer
Mar 8 at 0:14
add a comment |
I'm trying to manipulate an index and source array such that:
result[ i ][ j ][ k ] = source[ i ][ indices[ i ][ j ][ k ] ]
I know how to do this with for loops but I'm using giant arrays and I'd like to use something more time efficient. I've tried to use numpy's advanced indexing but I don't really understand it.
Example functionality:
source = [[0.0 0.1 0.2 0.3]
[1.0 1.1 1.2 1.3]
[2.0 2.1 2.2 2.3]]
indices = [[[3 1 0 1]
[3 0 0 3]]
[[0 1 0 2]
[3 2 1 1]]
[[1 1 0 1]
[0 1 2 2]]]
# result[i][j][k] = source[i][indices[i][j][k]]
result = [[[0.3 0.1 0.0 0.1]
[0.3 0.0 0.0 0.3]]
[[1.0 1.1 1.0 1.2]
[1.3 1.2 1.1 1.1]]
[[2.1 2.1 2.0 2.1]
[2.0 2.1 2.2 2.2]]]
python arrays numpy
I'm trying to manipulate an index and source array such that:
result[ i ][ j ][ k ] = source[ i ][ indices[ i ][ j ][ k ] ]
I know how to do this with for loops but I'm using giant arrays and I'd like to use something more time efficient. I've tried to use numpy's advanced indexing but I don't really understand it.
Example functionality:
source = [[0.0 0.1 0.2 0.3]
[1.0 1.1 1.2 1.3]
[2.0 2.1 2.2 2.3]]
indices = [[[3 1 0 1]
[3 0 0 3]]
[[0 1 0 2]
[3 2 1 1]]
[[1 1 0 1]
[0 1 2 2]]]
# result[i][j][k] = source[i][indices[i][j][k]]
result = [[[0.3 0.1 0.0 0.1]
[0.3 0.0 0.0 0.3]]
[[1.0 1.1 1.0 1.2]
[1.3 1.2 1.1 1.1]]
[[2.1 2.1 2.0 2.1]
[2.0 2.1 2.2 2.2]]]
python arrays numpy
python arrays numpy
asked Mar 7 at 23:44
Darci PDarci P
31
31
You needidx0 = np.r_['0,3,0', :3]. which is the same asnp.arange(3).reshape(3,1,1)Thenresult = source[idx0, indices]
– Paul Panzer
Mar 8 at 0:14
add a comment |
You needidx0 = np.r_['0,3,0', :3]. which is the same asnp.arange(3).reshape(3,1,1)Thenresult = source[idx0, indices]
– Paul Panzer
Mar 8 at 0:14
You need
idx0 = np.r_['0,3,0', :3]. which is the same as np.arange(3).reshape(3,1,1) Then result = source[idx0, indices]– Paul Panzer
Mar 8 at 0:14
You need
idx0 = np.r_['0,3,0', :3]. which is the same as np.arange(3).reshape(3,1,1) Then result = source[idx0, indices]– Paul Panzer
Mar 8 at 0:14
add a comment |
1 Answer
1
active
oldest
votes
Solution using Integer Advanced Indexing:
Given:
source = [[0.0, 0.1, 0.2, 0.3],
[1.0, 1.1, 1.2, 1.3],
[2.0, 2.1, 2.2, 2.3]]
indices = [[[3, 1, 0, 1],
[3, 0, 0, 3]],
[[0, 1, 0, 2],
[3, 2, 1, 1]],
[[1, 1, 0, 1],
[0, 1, 2, 2]]]
Use this:
import numpy as np
nd_source = np.array(source)
source_rows = len(source) # == 3, in above example
source_cols = len(source[0]) # == 4, in above example
row_indices = np.arange(source_rows).reshape(-1,1,1)
result = nd_source [row_indices, indices]
Result:
print (result)
[[[0.3 0.1 0. 0.1]
[0.3 0. 0. 0.3]]
[[1. 1.1 1. 1.2]
[1.3 1.2 1.1 1.1]]
[[2.1 2.1 2. 2.1]
[2. 2.1 2.2 2.2]]]
Explanation:
To use Integer Advanced Indexing, the key rules are:
- We must supply index arrays consisting of integer indices.
- We must supply as many of these index arrays, as there are dimensions in the source array.
- The shape of these index arrays must be the same, or, at least all of them must be broadcastable to a single final shape.
How the Integer Advanced Indexing works is:
Given that source array has n dimensions, and that we have therefore supplied n integer index arrays:
- All of these index arrays, if not in the same uniform shape, will be broadcasted to be in a single uniform shape.
- To access any element in the source array, we obviously need an n-tuple of indices. Therefore to generate the result array from the source array, we need several n-tuples, one n-tuple for each element-position of the final result array. For each element-position of the result array, the n-tuple of indices will be constructed from the corresponding element-positions in the broadcasted index arrays. (Remember the result array has exactly the same shape as the broadcasted index arrays, as already mentioned above).
- Thus, by traversing the index arrays in tandem, we get all the n-tuples we need to generate the result array, in the same shape as the broadcasted index arrays.
Applying this explanation to the above example:
- Our source array is
nd_source = np.array(source), which is 2d. Our final result shape is
(3,2,4).We therefore need to supply
2index arrays, and these index arrays must either be in the final result shape of(3,2,4), or broadcastable to the(3,2,4)shape.Our first index array is
row_indices = np.arange(source_rows).reshape(-1,1,1). (source_rowsis the number of rows in the source, which is3in this example) This index array has shape(3,1,1), and actually looks like[[[0]],[[1]],[[2]]]. This is broadcastable to the final result shape of(3,2,4), and the broadcasted array looks like[[[0,0,0,0],[0,0,0,0]],[[1,1,1,1],[1,1,1,1]],[[2,2,2,2],[2,2,2,2]]].Our second index array is
indices. Though this is not an array and is only a list of lists, numpy is flexible enough to automatically convert it into the corresponding ndarray, when we pass it as our send index array. Note that this array is already in the final desired result shape of(3,2,4)even without any broadcasting.Traversing these two index arrays in tandem (one a broadcasted array and the other as is), numpy generates all the 2-tuples needed to access our source 2d array
nd_source, and generate the final result in the shape(3,2,4).
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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%2f55054603%2findex-a-3d-array-with-2d-array-numpy%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Solution using Integer Advanced Indexing:
Given:
source = [[0.0, 0.1, 0.2, 0.3],
[1.0, 1.1, 1.2, 1.3],
[2.0, 2.1, 2.2, 2.3]]
indices = [[[3, 1, 0, 1],
[3, 0, 0, 3]],
[[0, 1, 0, 2],
[3, 2, 1, 1]],
[[1, 1, 0, 1],
[0, 1, 2, 2]]]
Use this:
import numpy as np
nd_source = np.array(source)
source_rows = len(source) # == 3, in above example
source_cols = len(source[0]) # == 4, in above example
row_indices = np.arange(source_rows).reshape(-1,1,1)
result = nd_source [row_indices, indices]
Result:
print (result)
[[[0.3 0.1 0. 0.1]
[0.3 0. 0. 0.3]]
[[1. 1.1 1. 1.2]
[1.3 1.2 1.1 1.1]]
[[2.1 2.1 2. 2.1]
[2. 2.1 2.2 2.2]]]
Explanation:
To use Integer Advanced Indexing, the key rules are:
- We must supply index arrays consisting of integer indices.
- We must supply as many of these index arrays, as there are dimensions in the source array.
- The shape of these index arrays must be the same, or, at least all of them must be broadcastable to a single final shape.
How the Integer Advanced Indexing works is:
Given that source array has n dimensions, and that we have therefore supplied n integer index arrays:
- All of these index arrays, if not in the same uniform shape, will be broadcasted to be in a single uniform shape.
- To access any element in the source array, we obviously need an n-tuple of indices. Therefore to generate the result array from the source array, we need several n-tuples, one n-tuple for each element-position of the final result array. For each element-position of the result array, the n-tuple of indices will be constructed from the corresponding element-positions in the broadcasted index arrays. (Remember the result array has exactly the same shape as the broadcasted index arrays, as already mentioned above).
- Thus, by traversing the index arrays in tandem, we get all the n-tuples we need to generate the result array, in the same shape as the broadcasted index arrays.
Applying this explanation to the above example:
- Our source array is
nd_source = np.array(source), which is 2d. Our final result shape is
(3,2,4).We therefore need to supply
2index arrays, and these index arrays must either be in the final result shape of(3,2,4), or broadcastable to the(3,2,4)shape.Our first index array is
row_indices = np.arange(source_rows).reshape(-1,1,1). (source_rowsis the number of rows in the source, which is3in this example) This index array has shape(3,1,1), and actually looks like[[[0]],[[1]],[[2]]]. This is broadcastable to the final result shape of(3,2,4), and the broadcasted array looks like[[[0,0,0,0],[0,0,0,0]],[[1,1,1,1],[1,1,1,1]],[[2,2,2,2],[2,2,2,2]]].Our second index array is
indices. Though this is not an array and is only a list of lists, numpy is flexible enough to automatically convert it into the corresponding ndarray, when we pass it as our send index array. Note that this array is already in the final desired result shape of(3,2,4)even without any broadcasting.Traversing these two index arrays in tandem (one a broadcasted array and the other as is), numpy generates all the 2-tuples needed to access our source 2d array
nd_source, and generate the final result in the shape(3,2,4).
add a comment |
Solution using Integer Advanced Indexing:
Given:
source = [[0.0, 0.1, 0.2, 0.3],
[1.0, 1.1, 1.2, 1.3],
[2.0, 2.1, 2.2, 2.3]]
indices = [[[3, 1, 0, 1],
[3, 0, 0, 3]],
[[0, 1, 0, 2],
[3, 2, 1, 1]],
[[1, 1, 0, 1],
[0, 1, 2, 2]]]
Use this:
import numpy as np
nd_source = np.array(source)
source_rows = len(source) # == 3, in above example
source_cols = len(source[0]) # == 4, in above example
row_indices = np.arange(source_rows).reshape(-1,1,1)
result = nd_source [row_indices, indices]
Result:
print (result)
[[[0.3 0.1 0. 0.1]
[0.3 0. 0. 0.3]]
[[1. 1.1 1. 1.2]
[1.3 1.2 1.1 1.1]]
[[2.1 2.1 2. 2.1]
[2. 2.1 2.2 2.2]]]
Explanation:
To use Integer Advanced Indexing, the key rules are:
- We must supply index arrays consisting of integer indices.
- We must supply as many of these index arrays, as there are dimensions in the source array.
- The shape of these index arrays must be the same, or, at least all of them must be broadcastable to a single final shape.
How the Integer Advanced Indexing works is:
Given that source array has n dimensions, and that we have therefore supplied n integer index arrays:
- All of these index arrays, if not in the same uniform shape, will be broadcasted to be in a single uniform shape.
- To access any element in the source array, we obviously need an n-tuple of indices. Therefore to generate the result array from the source array, we need several n-tuples, one n-tuple for each element-position of the final result array. For each element-position of the result array, the n-tuple of indices will be constructed from the corresponding element-positions in the broadcasted index arrays. (Remember the result array has exactly the same shape as the broadcasted index arrays, as already mentioned above).
- Thus, by traversing the index arrays in tandem, we get all the n-tuples we need to generate the result array, in the same shape as the broadcasted index arrays.
Applying this explanation to the above example:
- Our source array is
nd_source = np.array(source), which is 2d. Our final result shape is
(3,2,4).We therefore need to supply
2index arrays, and these index arrays must either be in the final result shape of(3,2,4), or broadcastable to the(3,2,4)shape.Our first index array is
row_indices = np.arange(source_rows).reshape(-1,1,1). (source_rowsis the number of rows in the source, which is3in this example) This index array has shape(3,1,1), and actually looks like[[[0]],[[1]],[[2]]]. This is broadcastable to the final result shape of(3,2,4), and the broadcasted array looks like[[[0,0,0,0],[0,0,0,0]],[[1,1,1,1],[1,1,1,1]],[[2,2,2,2],[2,2,2,2]]].Our second index array is
indices. Though this is not an array and is only a list of lists, numpy is flexible enough to automatically convert it into the corresponding ndarray, when we pass it as our send index array. Note that this array is already in the final desired result shape of(3,2,4)even without any broadcasting.Traversing these two index arrays in tandem (one a broadcasted array and the other as is), numpy generates all the 2-tuples needed to access our source 2d array
nd_source, and generate the final result in the shape(3,2,4).
add a comment |
Solution using Integer Advanced Indexing:
Given:
source = [[0.0, 0.1, 0.2, 0.3],
[1.0, 1.1, 1.2, 1.3],
[2.0, 2.1, 2.2, 2.3]]
indices = [[[3, 1, 0, 1],
[3, 0, 0, 3]],
[[0, 1, 0, 2],
[3, 2, 1, 1]],
[[1, 1, 0, 1],
[0, 1, 2, 2]]]
Use this:
import numpy as np
nd_source = np.array(source)
source_rows = len(source) # == 3, in above example
source_cols = len(source[0]) # == 4, in above example
row_indices = np.arange(source_rows).reshape(-1,1,1)
result = nd_source [row_indices, indices]
Result:
print (result)
[[[0.3 0.1 0. 0.1]
[0.3 0. 0. 0.3]]
[[1. 1.1 1. 1.2]
[1.3 1.2 1.1 1.1]]
[[2.1 2.1 2. 2.1]
[2. 2.1 2.2 2.2]]]
Explanation:
To use Integer Advanced Indexing, the key rules are:
- We must supply index arrays consisting of integer indices.
- We must supply as many of these index arrays, as there are dimensions in the source array.
- The shape of these index arrays must be the same, or, at least all of them must be broadcastable to a single final shape.
How the Integer Advanced Indexing works is:
Given that source array has n dimensions, and that we have therefore supplied n integer index arrays:
- All of these index arrays, if not in the same uniform shape, will be broadcasted to be in a single uniform shape.
- To access any element in the source array, we obviously need an n-tuple of indices. Therefore to generate the result array from the source array, we need several n-tuples, one n-tuple for each element-position of the final result array. For each element-position of the result array, the n-tuple of indices will be constructed from the corresponding element-positions in the broadcasted index arrays. (Remember the result array has exactly the same shape as the broadcasted index arrays, as already mentioned above).
- Thus, by traversing the index arrays in tandem, we get all the n-tuples we need to generate the result array, in the same shape as the broadcasted index arrays.
Applying this explanation to the above example:
- Our source array is
nd_source = np.array(source), which is 2d. Our final result shape is
(3,2,4).We therefore need to supply
2index arrays, and these index arrays must either be in the final result shape of(3,2,4), or broadcastable to the(3,2,4)shape.Our first index array is
row_indices = np.arange(source_rows).reshape(-1,1,1). (source_rowsis the number of rows in the source, which is3in this example) This index array has shape(3,1,1), and actually looks like[[[0]],[[1]],[[2]]]. This is broadcastable to the final result shape of(3,2,4), and the broadcasted array looks like[[[0,0,0,0],[0,0,0,0]],[[1,1,1,1],[1,1,1,1]],[[2,2,2,2],[2,2,2,2]]].Our second index array is
indices. Though this is not an array and is only a list of lists, numpy is flexible enough to automatically convert it into the corresponding ndarray, when we pass it as our send index array. Note that this array is already in the final desired result shape of(3,2,4)even without any broadcasting.Traversing these two index arrays in tandem (one a broadcasted array and the other as is), numpy generates all the 2-tuples needed to access our source 2d array
nd_source, and generate the final result in the shape(3,2,4).
Solution using Integer Advanced Indexing:
Given:
source = [[0.0, 0.1, 0.2, 0.3],
[1.0, 1.1, 1.2, 1.3],
[2.0, 2.1, 2.2, 2.3]]
indices = [[[3, 1, 0, 1],
[3, 0, 0, 3]],
[[0, 1, 0, 2],
[3, 2, 1, 1]],
[[1, 1, 0, 1],
[0, 1, 2, 2]]]
Use this:
import numpy as np
nd_source = np.array(source)
source_rows = len(source) # == 3, in above example
source_cols = len(source[0]) # == 4, in above example
row_indices = np.arange(source_rows).reshape(-1,1,1)
result = nd_source [row_indices, indices]
Result:
print (result)
[[[0.3 0.1 0. 0.1]
[0.3 0. 0. 0.3]]
[[1. 1.1 1. 1.2]
[1.3 1.2 1.1 1.1]]
[[2.1 2.1 2. 2.1]
[2. 2.1 2.2 2.2]]]
Explanation:
To use Integer Advanced Indexing, the key rules are:
- We must supply index arrays consisting of integer indices.
- We must supply as many of these index arrays, as there are dimensions in the source array.
- The shape of these index arrays must be the same, or, at least all of them must be broadcastable to a single final shape.
How the Integer Advanced Indexing works is:
Given that source array has n dimensions, and that we have therefore supplied n integer index arrays:
- All of these index arrays, if not in the same uniform shape, will be broadcasted to be in a single uniform shape.
- To access any element in the source array, we obviously need an n-tuple of indices. Therefore to generate the result array from the source array, we need several n-tuples, one n-tuple for each element-position of the final result array. For each element-position of the result array, the n-tuple of indices will be constructed from the corresponding element-positions in the broadcasted index arrays. (Remember the result array has exactly the same shape as the broadcasted index arrays, as already mentioned above).
- Thus, by traversing the index arrays in tandem, we get all the n-tuples we need to generate the result array, in the same shape as the broadcasted index arrays.
Applying this explanation to the above example:
- Our source array is
nd_source = np.array(source), which is 2d. Our final result shape is
(3,2,4).We therefore need to supply
2index arrays, and these index arrays must either be in the final result shape of(3,2,4), or broadcastable to the(3,2,4)shape.Our first index array is
row_indices = np.arange(source_rows).reshape(-1,1,1). (source_rowsis the number of rows in the source, which is3in this example) This index array has shape(3,1,1), and actually looks like[[[0]],[[1]],[[2]]]. This is broadcastable to the final result shape of(3,2,4), and the broadcasted array looks like[[[0,0,0,0],[0,0,0,0]],[[1,1,1,1],[1,1,1,1]],[[2,2,2,2],[2,2,2,2]]].Our second index array is
indices. Though this is not an array and is only a list of lists, numpy is flexible enough to automatically convert it into the corresponding ndarray, when we pass it as our send index array. Note that this array is already in the final desired result shape of(3,2,4)even without any broadcasting.Traversing these two index arrays in tandem (one a broadcasted array and the other as is), numpy generates all the 2-tuples needed to access our source 2d array
nd_source, and generate the final result in the shape(3,2,4).
edited Mar 9 at 10:43
answered Mar 8 at 1:51
fountainheadfountainhead
1,140212
1,140212
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f55054603%2findex-a-3d-array-with-2d-array-numpy%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
You need
idx0 = np.r_['0,3,0', :3]. which is the same asnp.arange(3).reshape(3,1,1)Thenresult = source[idx0, indices]– Paul Panzer
Mar 8 at 0:14