array-broadcasting

Can't use /= on numpy array

Can't use /= on numpy array Question: On a numpy array, why is it I can successfully use / 2: >>> a=np.array([2, 4, 6]) >>> a = a / 2 >>> a array([ 1., 2., 3.]) But I cannot use a /= 2? >>> a=np.array([2, 4, 6]) >>> a /= 2 Traceback (most recent call …

Total answers: 2

Finding max /min value of individual columns

Finding max /min value of individual columns Question: 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 snapshot of my data Frame is as follows: Asked By: SeleCoder || Source Answers: you can use pandas.DataFrame …

Total answers: 2

Broadcast an operation along specific axis in python

Broadcast an operation along specific axis in python Question: 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 to specify …

Total answers: 4

how to multiply pandas dataframe with numpy array with broadcasting

how to multiply pandas dataframe with numpy array with broadcasting Question: I have a dataframe of shape (4, 3) as following: In [1]: import pandas as pd In [2]: import numpy as np In [3]: x = pd.DataFrame(np.random.randn(4, 3), index=np.arange(4)) In [4]: x Out[4]: 0 1 2 0 0.959322 0.099360 1.116337 1 -0.211405 -2.563658 -0.561851 …

Total answers: 2