Questions tagged [elementwise-operations]

204 questions
2
votes
1 answer

Element-wise division between two dataframes with tickers and Date index

I have two dataframes with Date as index, df1 as follows: ticker AAPL AMD BIDU GOOGL IXIC MSFT Date 2011-06-29 0.017664 0.024379 0.029592 …
2
votes
3 answers

How to map a states table to life table in numpy?

The problem and what I expect. I have a table h which indicates the H-bond states, where 1 for existing H-bond, 0 for no H-bond exist. Colums are for different object, rows are for different time step. 0, 0, 1, 1, 0, 0 0, 0, 1, 1, 0, 0 1, 0, 1, 1,…
2
votes
1 answer

Logical AND operation across multiple lists

I have a dictionary that looks something like: d= {'GAAP':[True,True],'L1':[True,False],'L2':[True,True]} I would like to perform a logical AND operation across each of the values in the dictionary and return a LIST of True/False values. Something…
Number Logic
  • 852
  • 1
  • 9
  • 19
2
votes
1 answer

Custom algorithm to deal with negative values within a DataFrame

To start, I have a DataFrame that looks like the following: df = pd.DataFrame({'a': [25, 22, -2, 16, 10], 'b': [-5, 18, -2, 25, 48], 'c': [34, -12, 7, 8, 22], 'd': [10, 8, -2, -4, 12]}) Goal: Eliminate all zeroes using a specific script or…
2
votes
3 answers

How to efficiently multiply every element in a 2-dimensional array by a 1-dimensional array in Numpy?

I would like to efficiently multiply every element in a 2D array with a 1D array using numpy, so that a 3D array is returned. Basically, the code should do something like: import numpy as np #create dummy…
2
votes
6 answers

Concatenate two lists elementwise to an n x n matrix

I have two lists with strings which I want to concatenate elementwise into a n x n matrix. I have tried the below code but this only gives me n x 1 list. row = ['a','b','c'] col = ['a','b','c'] matrix = map(''.join, zip(row,col)) The expected…
Anders
  • 89
  • 9
2
votes
1 answer

Numpy elementwise multiplication (unexpected integer overflow)

I'm using Python 3.7 and numpy 1.15.2 and have encountered a behavior in elementwise multiplication that I don't understand. The following is intuitive to me: import numpy as np a = np.array([[30000,4000]]) b =…
2
votes
1 answer

How to get Mean & Std of multiple numpy saved arrays using element-wise operation

I have a folder with 1000 numpy compressed files (npz) representing the results of a data simulation. Each file has two arrays a and b, with same dimension, shape, data type. What I want as a final output is the element-wise mean and standard…
renan-brso
  • 149
  • 3
  • 11
2
votes
2 answers

Multiply each element of a vector by each element of another vector

I have two very big column vectors, A and B, of size ax1 and bx1, respectively. I want to construct a vector C of size (b*a)x1 by computing A(i)*B(j) for each i and j. To illustrate what I…
TEX
  • 2,249
  • 20
  • 43
2
votes
2 answers

Element-wise maximum with key

is there a more efficient way to perform element-wise maximum with key? import numpy as np a = np.array([-2, 2, 4, 0]) b = np.array([-3,-5, 2, 0]) c = np.array([ 1, 1, 1, 1]) mxs = np.empty((4,)) for i in range(4): mxs[i] = max([a[i], b[i],…
Low Yield Bond
  • 327
  • 5
  • 10
2
votes
1 answer

2d array compare to 1d array returns 2d array

I am trying to compare a 1D array element-wise to a 2D array, and returns the elements of the 2D array which fulfils the condition in a 2D array form without using a for loop. Preferably using numpy or quicker method. a = range(1,10) Tna =…
2
votes
2 answers

Element-wise mutiplication .* of vectors gives matrix in Matlab

Given two vectors a = 1:3; b = 2:4; it's well known that the element-wise mutiplication a.*b produces [ 2 6 12 ] Calling that result c, we have c(i) = a(i)*b(i) But I don't understand how a.*b', b'.*a and b'*a all produce [ 2 4 6 3 …
wsdzbm
  • 3,096
  • 3
  • 25
  • 28
2
votes
2 answers

Python: how to get element-wise standard deviation of multiple arrays in a dataframe

I have a rather big dataframe (df) containing arrays and NaN in each cell, the first 3 rows look like this: df: A B C X [4, 8, 1, 1, 9] NaN [8, 2, 8, 4, 9] Y [4, 3, 4, 1, 5] [1, 2, 6,…
2
votes
2 answers

Comparing arrays and adding to different elements?

z = np.array([1, 2, 3, 4]) x = np.array([4, 2, 3, 5]) n = 1 I want to compare these two arrays element wise and I want to add n to only those elements of z that are different to those of x. Answer should be: z = [2, 2, 3, 5]
Charles B
  • 95
  • 3
  • 14
2
votes
1 answer

Pandas multiply DataFrames with element-wise match of index and column

I have two pandas DataFrames, with one of them having index and columns that are subsets of the other. For example: DF1 = date a b c 20170101 1.0 2.2 3 20170102 2.1 5.2 -3.0 20170103 4.2 1.8 10.0 ... 20170331 9.8 …
Zhang18
  • 4,800
  • 10
  • 50
  • 67