array-broadcasting Questions
5
What is numpy.newaxis and when should I use it?
Using it on a 1-D array x produces:
>>> x
array([0, 1, 2, 3])
>>> x[np.newaxis, :]
array([[0, 1, 2, 3]])
>>> x[:, np.new...
Grosvenor asked 24/3, 2015 at 19:18
4
Solved
In python, suppose I have a square numpy matrix X, of size n x n and I have a numpy vector a of size n.
Very simply, I want to perform a broadcasting subtraction of X - a, but I want to be able t...
Brahmanism asked 7/9, 2016 at 4:41
2
Solved
I am a beginner to Data Analysis using Python and stuck on the following:
I want to find maximum value from individual columns (pandas.dataframe) using Broadcasting /Vectorization methodology.
A sn...
Linguini asked 30/10, 2017 at 0:19
2
Solved
I have a 3x1 point vector representing the start point of some line, and a 3x1 point vector representing the end of some line. I would like to sample an arbitrary amount of points along the line co...
Paramount asked 15/3, 2018 at 18:22
2
Solved
torch.add(torch.ones(4,1), torch.randn(4))
produces a Tensor with size: torch.Size([4,4]).
Can someone provide a logic behind this?
Unexacting asked 16/7, 2018 at 22:53
1
The term broadcasting describes how numpy treats arrays with different shapes during arithmetic operations.
Example 1:
from numpy import array
a = array([1.0,2.0,3.0])
b = array([2.0,2.0,2....
Differential asked 15/11, 2017 at 14:20
3
Solved
I'm having some trouble understanding the rules for array broadcasting in Numpy.
Obviously, if you perform element-wise multiplication on two arrays of the same dimensions and shape, everything is ...
Cornered asked 24/6, 2012 at 14:16
1
I am trying to multiply a 3D array by a 1D array, such that each 2D array along the 3rd (depth: d) dimension is calculated like:
1D_array[d]*2D_array
And I end up with an array that looks like, s...
Homicide asked 25/1, 2013 at 0:13
5
Solved
I would like to raise a vector by ascending powers form 0 to 5:
import numpy as np
a = np.array([1, 2, 3]) # list of 11 components
b = np.array([0, 1, 2, 3, 4]) # power
c = np.power(a,b)
desired ...
Pegu asked 17/2, 2021 at 13:3
3
Solved
Suppose I have a numpy array x of shape [1,5]. I want to expand it along axis 0 such that the resulting array y has shape [10,5] and y[i:i+1,:] is equal to x for each i.
If x were a pytorch tensor ...
Mayoralty asked 10/12, 2020 at 12:42
3
Solved
For example, trying to make sense of these results:
>>> x
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> (x == np.array([[1],[2]])).astype(np.float32)
array([[ 0., 1., 0., 0., 0., 0.,...
Mufti asked 14/2, 2016 at 20:47
1
Solved
I have to sum 2 arrays with broadcasting. This is the first:
a = [0 1 2 3]
And this is the second:
A = [[ 0 1 2 3 4 5]
[ 6 7 8 9 10 11]
[12 13 14 15 16 17]
[18 19 20 21 22 23]]
This is t...
Lantz asked 27/7, 2020 at 16:49
4
Solved
I have a rgb semantic segmentation label, if there exists 3 classes in it, and each RGB value is one of:
[255, 255, 0], [0, 255, 255], [255, 255, 255]
respectively, then I want to map all values...
Effusion asked 30/10, 2018 at 7:19
0
I am working on a web-API access package in Julia, following fairly standard REST.
It has lots of methods like:
post_foo(cred::ServiceCred, x, y)
get_foo(cred::ServiceCred, x, y)
Sometimes I wou...
Texas asked 9/5, 2020 at 19:40
2
Solved
I'm trying to take advantage of NumPy broadcasting and backend array computations to significantly speed up this function. Unfortunately, it doesn't scale so well so I'm hoping to greatly improve t...
Sheathe asked 7/4, 2020 at 22:39
3
Solved
I have a numpy 1D array of z values, and I want to calculate the difference between all combinations of the entries, with the output as a square matrix.
I know how to calculate this as a distance...
Cumulation asked 2/12, 2019 at 22:44
1
Solved
Today I noticed something odd in my code, and discovered that in certain situations it run down to the execution of the following:
my_list = [0] + np.array([])
which results in my_list being the...
Oleaceous asked 14/11, 2019 at 10:33
3
Solved
Is there a way to add (as opposed to sum) multiple arrays together in a single operation? Obviously, np.sum and np.add are different operations, however, the problem I'm struggling with right now i...
Favored asked 25/9, 2019 at 3:11
1
Solved
I'm trying to create a numpy array that looks like
array([[list([]), list([])],
[list([]), list([])],
[list([]), list([])]], dtype=object)
This array has shape (3,2). However, whenever I do
...
German asked 5/8, 2019 at 18:26
4
Solved
I need to create a 2D array where each row may start and end with a different number. Assume that first and last element of each row is given and all other elements are just interpolated according ...
Nautch asked 16/11, 2016 at 5:2
3
Solved
I have the following code. It is taking forever in Python. There must be a way to translate this calculation into a broadcast...
def euclidean_square(a,b):
squares = np.zeros((a.shape[0],b.shape[...
Patel asked 26/3, 2016 at 22:27
3
Is there a way to use np.newaxis with Numba nopython ? In order to apply broadcasting function without fallbacking on python ?
for example
@jit(nopython=True)
def toto():
a = np.random.randn(20,...
Motch asked 4/8, 2016 at 7:21
4
Solved
Given two matrices, I want to compute the pairwise differences between all rows. Each matrix has 1000 rows and 100 columns so they are fairly large. I tried using a for loop and pure broadcasting b...
Adai asked 24/3, 2017 at 4:18
2
Solved
I came across something curious (to me) while trying to answer this question.
Say I want to compare a series of shape (10,) to a df of shape (10,10):
np.random.seed(0)
my_ser = pd.Series(np.rando...
Skidway asked 17/2, 2019 at 8:13
3
Solved
I am trying to remove the loop from this matrix multiplication (and learn more about optimizing code in general), and I think I need some form of np.broadcasting or np.einsum, but after reading up ...
Sefton asked 7/12, 2018 at 20:38
1 Next >
© 2022 - 2024 — McMap. All rights reserved.