Skip to main content
Stack Overflow
  1. About
  2. For Teams
Filter by
Sorted by
Tagged with
1 vote
1 answer
57 views

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

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

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

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

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

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

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

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

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

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....
lima0's user avatar
  • 121
6 votes
1 answer
2k views

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

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

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

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

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,...

15 30 50 per page
1
2 3 4 5
...
21

AltStyle によって変換されたページ (->オリジナル) /