Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
62 views

Is there a way to simultaneously broadcast rows and columns? The following MWE does not work: #include <iostream> #include <Eigen/Dense> int main() { std::cout << "Hello, ...
KeynesCoeFen's user avatar
1 vote
1 answer
91 views

The following code multiplies the i-th column of A by the i-th element of V. #include <Eigen/Core> Eigen::Array<double, 8, 2> f(const Eigen::Array<double, 8, 2>& A, const Eigen::...
YiFei's user avatar
  • 1,878
1 vote
1 answer
82 views

Say I have a Numpy array of 500 lists with random sizes ranging from 0 to 9: import numpy as np a = np.array([[i for i in range(np.random.randint(10))] for _ in range(500)], dtype=object) Now I want ...
Shaun Han's user avatar
  • 2,965
2 votes
1 answer
76 views

I have two numpy arrays a and b such that a.shape[:-1] and b.shape are broadcastable. With this constraint only, I want to calculate an array c according to the following: c = numpy.empty(numpy....
Quercus Robur's user avatar
0 votes
2 answers
100 views

I often find myself to broadcast 1d arrays into a specific dimension dim_a given a total number of dimension dim_total. What I mean is the following: import numpy as np a = np.arange(10) dim_a = 2 ...
Axel Donath's user avatar
  • 1,941
2 votes
1 answer
76 views

I was learning boolean indexing in numpy and came across this. How is the indexing below not producing a Index Error as for axis 0 as there are only two blocks? x = np.arange(30).reshape(2, 3, 5) x ...
Harmanpreet Singh's user avatar
0 votes
0 answers
54 views

I am writing a function to bin points based on their angle in a radial coordinate system. I would like to have the option to perform some nonlinear downsampling of the points in each bin (computing ...
Gtingstad's user avatar
1 vote
2 answers
43 views

I have a zero-dimensional numpy scalar s and a two-dimensional numpy matrix m. I want to form a matrix of vectors in which all the elements of m are paired with s as in the following example: import ...
Ben's user avatar
  • 539
-1 votes
1 answer
80 views

I wrote a python function I would expect to allow vectorization, using np.where and np.maximum. However, when attempting to call that function by passing dataframe columns, I get the error "...
rdsencap's user avatar
0 votes
1 answer
55 views

I am trying to avoid a for loop by using array broadcasting in order to save time. My setup is as follows: I have a column array of length n where each element is a mxm array (which I'll call A) and ...
roshoka's user avatar
  • 181
0 votes
1 answer
77 views

I've Googled and asked ChatGPT and looked through NumPy docs and can't find any way to do this, so thought I'd ask here. Suppose I have a 4-dimensional array -- in this case, of shape (3, 2, 2, 2): a =...
crazygringo's user avatar
  • 1,375
1 vote
2 answers
102 views

I'm working on a personal project for computing and manipulating integer distributions, for application in systems like DnD and pathfinder. I'm looking to make functions that can query the probability ...
Minty's user avatar
  • 53
3 votes
2 answers
73 views

I have a function which can take an np.ndarray of shape (3,) or (3, N), or (3, N, M), etc.. I want to add to the input array an array of shape (3,). At the moment, I have to manually check the shape ...
Alex V.'s user avatar
  • 466
1 vote
1 answer
69 views

I have two numpy.ndarray instances with different shapes. If I add these two arrays, broadcasting will occur between them: import numpy as np x = np.array([1, 2, 3]) y = np.array([[2, 3, 5], ...
dolmok's user avatar
  • 178
0 votes
1 answer
100 views

I am trying to implement a multi-frequency phase unwrapping algorithm using Python3 and NumPy. I have 7 single channel (gray scale) images of shape (1080, 1920). After stacking them along the third ...
Arun's user avatar
  • 2,518
1 vote
0 answers
126 views

I'm trying to use numpy-like syntax on an awkward.Array with variable sizes in the second dimension, but it's still confusing.. In numpy i have normals.shape # (N,3) idcs.shape # (m,k) normals[idcs]...
Nico's user avatar
  • 11
4 votes
1 answer
226 views

I have a somewhat peculiar structure of python list of lists that I need to convert to a numpy array, so far I have managed to simply get by using np.array(myarray, dtype = object), however a ...
Arran's user avatar
  • 95
0 votes
0 answers
64 views

Does anybody have an explanation for the unexpected numpy slicing results dislplayed below ? Unexpected behavior demo import torch import numpy as np some_array = np.zeros((1, 3, 42)) chooser_mask = ...
n0tis's user avatar
  • 838
0 votes
2 answers
136 views

Consider the following in Python: A has dimension (T,), U has dimension (L,T) and G has dimension (K,T), Y is (L,L,T). My code outputs a numer1 and numer2 with dimensions (T, LK, 1), . Consider that ...
user9875321__'s user avatar
0 votes
1 answer
99 views

I have a numpy array A with shape (a, b, c), and another integer array L with shape (a, b). I want to make an array B such that B[i, j, k] = A[L[i, j],j, k] (assume shapes and values of L permit this)....
Danny Duberstein's user avatar
1 vote
2 answers
56 views

I want to achieve the following result fast for i in range(n): C[index[i]] += A[i] where C is an d * m matrix, index is an array containing n integers ranging in [0, d), and A is an n * m matrix. ...
Chenming Zhang's user avatar
1 vote
0 answers
37 views

I am trying to make a N-body simulator that takes initial position and velocity and with output of position respect to time. I used create a function that produce the differential equation of velocity ...
DL_921221's user avatar
-1 votes
1 answer
243 views

I am trying to understand Numpy Broadcasting. So I want to understand why is the below code working? a = np.arange(4).reshape(2,2) b = np.arange(6).reshape(3,2) a = a[:, np.newaxis] a + b I mean if ...
user3851878's user avatar
2 votes
3 answers
92 views

I have to perform the operation below many times. Using numpy functions instead of loops I usually get a very good performance but I have not been able to replicate this for higher dimensional arrays. ...
Delosari's user avatar
  • 693
0 votes
1 answer
61 views

I'm new to Fortran and I already have a hard time understanding the concept of broadcasting of arrays in Python, so it is even more difficult for me to implement it in Fortran Fortran code: program ...
Jakob Primosch's user avatar
0 votes
3 answers
113 views

Consider the code below which gives the wanted output: import numpy as np import pandas as pd sumvalues = 2 touchdown = 3 arr = np.array([1, 2, 3, 4, 5, 6, 7]) series = pd.Series(arr) shifted = pd....
spline regressor's user avatar
1 vote
1 answer
45 views

how can i find dot product of each batch response and X data. y_yhat_allBatches_matmulX_allBatches = torch.matmul(yTrue_yHat_allBatches_tensorSub, interceptXY_data_allBatches[:, :, :-1]) expected ...
sahuno's user avatar
  • 473
2 votes
1 answer
80 views

I have an array x of shape (N, T, d). I have two functions f and g which both take an array of shape (some_dimension, d) and return an array of shape (some_dimension, ). I would like to compute f on ...
Euler_Salter's user avatar
  • 3,601
0 votes
1 answer
106 views

I have a numpy matrix of shape m * n * n, meaning I have m n*n square matrices. For each matrix, I must have elements present in such a way so that the transpose indexes are reciprocal of each other. ...
EESHAN ANAND's user avatar
2 votes
1 answer
186 views

numpy.broadcasting allows to perform basic operations (additions, multiplication, etc.) with arrays of different shapes (under certain conditions on these shapes). For example: >>> a = np....
Guillaume Mougeot's user avatar
1 vote
1 answer
63 views

I'm trying to write the following expression using the einsum function in NumPy: for j in range(100): p[j] = 0 for i in range(100): if i!=j: p[j] += S[i,j]*B[T[i,j], i] p....
FatPanda01's user avatar
2 votes
2 answers
84 views

The following is a seemingly simple recursion for finding a hybercube matrix. The recursion is defined as: (Formula) I tried to put it into code but I keep running into broadcasting issues with numpy. ...
mo-alowais's user avatar
0 votes
1 answer
110 views

I am implementing the dilated k-nearest neighbors algorithm. The algorithm unfortunately has nested loops. The presence of loops severely hampers the execution speed. import torch dilation=3 nbd_size=...
Aleph's user avatar
  • 207
0 votes
1 answer
76 views

Example of what I want to compare these two: torch.tensor([[1,2],[1,2],[1,3]]) == torch.tensor([1,2]) I want this output: [True, True, False] But instead the broadcasting gets me: tensor([[ True, ...
JobHunter69's user avatar
  • 2,376
0 votes
1 answer
550 views

I am in the early stages of learning Pytorch for deep learning and have come across something I don't understand. I have written a very simple script to just make sure I fully understand the ...
Bruck's user avatar
  • 33
0 votes
0 answers
34 views

Given an array of points with shape (2, n) the function returns the n interpolated values. The function should also work if points is a 1-d array (2,). I think numba vectorize could be used to solve ...
Max Frankenberg's user avatar
0 votes
1 answer
239 views

I have two large equal size 2D numpy arrays of cartesian vectors: A = [[ax1, ay1, az1], [a2], [a3], ...] where a1 = [ax1, ay1, az1] B = [[bx1, by1, bz1], [b2], [b3], ...] where b1 = [bx1, by1, bz1] I ...
Mark Huisjes's user avatar
1 vote
2 answers
81 views

I have an array of tuples, I need to find the tuple from that array that is the closes to a given tuple(element wise), that is by the absolute value difference between each element of these two tuples....
Josh's user avatar
  • 314
1 vote
2 answers
76 views

Problem I am trying to avoid a for loop in NumPy (which is quite messy and obviously performance prohibiting). My challenge is that operations on each row depend on other rows. That is: I have a (very ...
Sterling Butters's user avatar
0 votes
1 answer
70 views

Problem: A is a multidimensional array of two dimensions (i,j) and B is a boolean array of the same shape that I want to define according to the values of A. I want to define B through two ...
Puco4's user avatar
  • 673
2 votes
3 answers
417 views

I want to construct a matrix of shape (N,2N) in Python. I can construct the matrix as follows import numpy as np N = 10 # 10,100,1000, whatever some_vector = np.random.uniform(size=N) some_matrix ...
user1887919's user avatar
0 votes
1 answer
235 views

Why do I get this error only for x_train? On commenting x_train out, no errors come. --------------------------------------------------------------------------- TypeError ...
Daksh's user avatar
  • 1
0 votes
1 answer
37 views

I am trying to rewrite an numpy function such that it can deal with 2d and 3d inputs. Consider the following code: import numpy as np def adstock_geometric(x: np.array, theta: np.array): x_decayed ...
richard baws's user avatar
0 votes
1 answer
138 views

I'm trying to find knn for grid points. This is the code for generating the grid def grid_by(lims=[[0, 1], [0, 1]], size=[28, 28]): """ Creates a tensor of 2D grid points. ...
Hajin Lee's user avatar
  • 199
1 vote
1 answer
113 views

I need to calculate a moving average over a 3D array with a step size set by me. What I am doing right now is img = np.ones(10,10,50) img_new = bottleneck.move.move_mean(img, window=5, axis=2) ...
emely_pi's user avatar
  • 701
0 votes
1 answer
38 views

I was trying to perform mean clustering on my dataset. The dataset X is of the dimension (182,108,130). The mean is calculated using np.mean(X, axis = 1). The mean is of dimension (182,130). Now I'd ...
HSCLHD's user avatar
  • 23
0 votes
1 answer
252 views

Why is the explicit dimension expansion so space inefficient as compared to leveraging implicit numpy broadcasting, which technically does the same thing i.e. copies the matrix over on a given ...
A. Boa's user avatar
  • 3
0 votes
1 answer
69 views

I have two matrices A and B of dimensions (n_m, n_u) and (n_m, n). I want a 3D matrix with dimensions (n, n_m, n_u) such that the first column of B is multiplied (element-wise) with every column of A ...
Shashwat Gupta's user avatar
0 votes
1 answer
42 views

I have an array like so: data = np.array([ [[10, 10, 10], [10, 10, 10], [10, 10, 10]], [[20, 20, 20], [20, 20, 20], [20, 20, 20]], [[30, 30, 30], [30, 30, 30], ...
Edy Bourne's user avatar
  • 6,306
0 votes
1 answer
126 views

I have a 3d numpy array and a list of columns (axis = 1) in which I would like to replace all zeroes by a constant value: My sample data is like so: data = np.array([ [[10, 10, 10], [0, 10, 10], [...
Edy Bourne's user avatar
  • 6,306

1
2 3 4 5
19