Questions tagged [elementwise-operations]
204 questions
0
votes
1 answer
Split factor column into several columns in R
I want to multiply regression coefficients with the actual variables for every observation. Without factors, I can do this by multiplying the matrix of variables element wise with the vector of coefficients
v_coef <- as.matrix(vars) %*%…

Kevin
- 61
- 4
0
votes
1 answer
combine numpy array "element-wise"
Currently I have two arrays: the shape of a1 is (5,4,6,3), the second one a2 is (5,4,6) and finally I want to get a merged array (5,4,6,4)
Currently I "for-loop" each (6,3) array and np.stack it with corresponding (6,1) to (6,4).
for i in…

Michael Sun
- 61
- 5
0
votes
1 answer
Multiply tibbles elementwise
I have two tibbles (equal number of rows and columns) like this:
first <- tibble::tribble(
~date, ~col1, ~col2,
"2000-01-01", 8.2, 10.10,
"2000-01-02", 3.2, 20.30,
"2000-01-03", 2.3, …
user8934968
0
votes
3 answers
How to calculate a row-wise count of duplicates based on (element-wise) selected adjacent columns
I have a data frame test:
group userID A_conf A_chall B_conf B_chall
1 220 1 1 1 2
1 222 4 6 4 4
2 223 6 5 3 2
1 224 1 5 4 4
2 …

Sandy
- 1,100
- 10
- 18
0
votes
0 answers
Elementwise multiplication with pytorch weights
I am trying to build a simple "neural network" with just elementwise multiplication with weights.
Just for this scenario I have a data with 5 features which only one is "1" and all the rest are "0" (one hot encoded), and I am trying to predict with…

Codevan
- 538
- 3
- 20
0
votes
2 answers
Numpy - multiply 3D array(100,100,3) with 2D array(100,100)
I am solving quite trivial problem. I can solve it through iteration, but its too slow.
My problem:
import numpy as np
arr3 = np.zeros(shape=[4, 4, 3])
arr2 = np.zeros(shape=[4, 4])
#This is ok but I dont want
arr3[0,0]*arr2[0,0] # thats…

Martin
- 3,333
- 2
- 18
- 39
0
votes
3 answers
Numpy automatic elementwise function
I have a question regarding numpy.
Let's assume I have a function
def calcSomething(A,t):
return t*A
I want to pass A a constant numpy-array, e.g. A=np.array([1.0,2.0]) and t as equidistant points, e.g. t = np.linspace(0.0,1.0,10).
Now, when…

J.Doe
- 69
- 2
- 7
0
votes
2 answers
Checking element-wise whether two arrays share at least one element in Java
I'm trying to find an efficient way in Java to check whether two arrays have at least one element in common element-wise. So this means [1, 2, 2, 3] and [2, 3 ,5 ,6] would give False, whereas [1, 2, 2, 3] compared with [5, 2, 1, 5] would give True.…

blah_crusader
- 424
- 1
- 5
- 14
0
votes
1 answer
How can I apply a custom scalar function elementwise to a matrix in math.js?
Consider the matrix m:
let m = [ [ 1 , 2 ] , [ 3 , 4 ] ]
Apply the exponentiation function to m:
let mexp = math.exp(m)
Now JSON.stringify(mexp) outputs:
"[[2.718281828459045,7.38905609893065],[20.085536923187668,54.598150033144236]]"
So the…

sbtpr
- 541
- 5
- 18
0
votes
1 answer
Element-wise power using OpenCV
I am currently reading this book. The author wrote a code snippet on page 83 in order to (if i understand it correctly) calculate the element-wise power of two matrices. But i think the code doesn't fulfill its purpose because the matrix dst does…

Shihao Xu
- 721
- 1
- 7
- 14
0
votes
3 answers
Python: Element-wise implementation of 'in' conditional operator
So, I have two lists:
x =[170 169 168 167 166 165 183 201 219 237 255 274 293 312 331 350]
y =[201,168]
I want to write a conditional if statement that is true only if all the contents of y are in x. How do I do this?
E.g. -- assert(y[0] in x) and…

ap21
- 2,372
- 3
- 16
- 32
0
votes
2 answers
A fast way to multiply a NumPy array of scalars by an array of arrays
What is the most concise way to carry out multiplication like this?
# c's are scalars (or arrays like A's in general)
x = np.array([c1, c2, c3])
# A's are NumPy arrays
M = np.array([A1, A2, A3])
to get
x*M = [c1*A1, c2*A2, c3*A3]
c's are scalars,…

homocomputeris
- 509
- 5
- 18
0
votes
4 answers
tensorflow: how to perform element-wise multiplication between two sparse matrix
I have two sparse matrices declared using the tf.sparse_placeholder. I need to perform the element-wise multiplication between the two matrices. But I cannot find such an implementation in tensorflow. The most related function is…

pfc
- 1,831
- 4
- 27
- 50
0
votes
3 answers
Element wise, variable combination of lists in python
Preface: Element-wise addition of 2 lists?
I want to write to code to have the following behavior:
[ 1, 1, ["Alpha"]]
+
[ 2, 2, ["Beta"] ]
|| || ||
\/ \/ \/
[3, 3, ["Alpha", "Beta"]]
in python. Is this possible without very…

Erich
- 1,902
- 1
- 17
- 23
0
votes
1 answer
Tensorflow define a operation that builds the product of all tensor components
I want to define a operation in tensorflow that calculates something like:
x is provided by a tensor. Finally the operation should be compared to a known value and parameters alpha, beta i and b should be learned.
(I guess) The product of all…

user2129910
- 33
- 1
- 6