303 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
1
vote
1
answer
57
views
unexpected results when using normal and advanced indexing with numpy
Consider the following:
import numpy as np
a = np.random.rand(123, 45, 3)
print(a[:, :, [0, 1]].shape) # (123, 45, 2)
print(a[:, 0, [0, 1]].shape) # (123, 2)
print(a[0, :, [0, 1]].shape) # (2, 45)...
0
votes
2
answers
65
views
Performance degradation of matrix multiplication involving integer-array-indexed arrays in numpy
I'm working on a project where I have to perform some row and/or column permutaion before (broadcasted) matrix multiplication. While the implementation is straightforward with numpy, I noticed that ...
-1
votes
1
answer
513
views
How to convert topk data from torch.tensor.topk() to a pytorch tensor
I have a 1-d pytorch tensor and I got topk data of the tensor and indeces of this datas. How can I place each data in the corresponding position of a empty pytorch tensor?
The topk of this tensor ...
0
votes
1
answer
75
views
Using numpy, what is a good way to index into a matrix using another matrix whose entry values are column numbers?
Suppose I want to indepedently re-order each row of a matrix. Here is an example of that using np.argsort():
>>> A
array([[88, 44, 77, 33, 77],
[33, 55, 66, 88, 0],
[88, 0, 0,...
0
votes
1
answer
474
views
Fastest way to write in an numpy array at specific indexes?
I would like to get the fastest solution to write data in a 2D numpy array using an array of indexes.
I have a large 2D boolean numpy array buffer
import numpy as np
n_rows = 100000
n_cols = 250
...
0
votes
1
answer
472
views
How to access multiple elements in c++ Eigen array?
I want to retrieve certain elements in an Eigen array and return them as a vector. I use the following code:
Eigen::ArrayXXi test;
test.resize(5,5);
test.setRandom();
Eigen::Matrix<int, 2, 3> ...
0
votes
2
answers
79
views
Getting a subset of numpy array indicies an easy way
Can this for loop be written in a simpler way?
import itertools
import numpy as np
def f(a, b, c): # placeholder for a complex function
print(a+b+c)
a = np.arange(12).reshape(3, 4)
for y, x in ...
1
vote
1
answer
1k
views
Matrix index out of range during loop
a is an nxn matrix.
I have this code:
[m,n] = size(a);
x = zeros(m,1);
for j=1:1:n
if(j==1)
a(1,:) = [];
else
end
disp(a);
a(:,j) = [];
disp(x);
disp(a); ...
2
votes
0
answers
7k
views
How to modify a masked array in place directly by assigning to it using advanced indexing
I have an array that I want to change some values on some rows. The desired rows will be addressed by a Boolean masked array. Then I want to modify one of the values in the rows:
a = np.array([[0., 0.]...
2
votes
1
answer
1k
views
How to sort a one hot tensor according to a tensor of indices
Given the below tensor:
tensor = torch.Tensor([[1., 0., 0., 0., 0.],
[0., 1., 0., 0., 0.],
[0., 0., 1., 0., 0.],
[0., 0., 0., 0., 1....
6
votes
1
answer
2k
views
Use a BitArray in Julia to filter rows of an array
I'd like to filter each row of my matrix a such that each row contains non-negative values.
First, I tried this:
julia> a = [-1 2 3; 4 5 6; -5 3 4; 3 5 ×ばつ3 Matrix{Int64}:
-1 2 3
4 5 6
-5 ...
1
vote
1
answer
139
views
Flat indexing of all but first dimension with Numpy
Is there some way to use flat indexing for the remaining dimensions with NumPy? I'm trying to translate the following MATLAB function to Python
function [indices, weights] = locate(values, gridpoints)
...
0
votes
1
answer
468
views
Indexing a 4D NumPy Array with two 2D arrays
I have a 4D target NumPy array which I want to fill with values from a 2D source array, using two additional 2D arrays which specify the position in the second and third axis of the target array where ...
0
votes
1
answer
62
views
Equivalent of NumPy index arrays with standard Python lists or arrays
I can use an array or a list to index into numpy.array, e.g.:
a = np.array([1, 2, 3, 4])
print(a[[1, 3]])
will produce
[2 4]
Is there an equivalent construct to index into a standard Python list or ...
0
votes
1
answer
253
views
Accessing an individual element in a Numpy array of arbitrary dimensions
So. I am trying to access and modify the penultimate individual element of a series of Numpy arrays.
array_1D = np.array([10,11,12,13, 14])
array_2D = np.array([[20,30,40,50,60], [43,54,65,76,87], [11,...