Questions tagged [elementwise-operations]

204 questions
1
vote
2 answers

Python or Numpy Approach to MATLAB's "cellfun"

Is there a python or numpy approach similar to MATLABs "cellfun"? I want to apply a function to an object which is a MATLAB cell array with ~300k cells of different lengths. A very simple example: >>> xx = [(4,2), (1,2,3)] >>> yy =…
rakbar
  • 103
  • 1
  • 2
  • 7
1
vote
1 answer

Vectorized Evaluation of a Function, Broadcasting and Element Wise Operations

Given this... I have to explain what this code does, knowing that it performs the vectorized evaluation of F, using broadcasting and element wise operations concepts... def F(x_pos, alpha): D = x_pos.reshape(1,-1) - x_pos.reshape(-1,1) …
Patricio Sard
  • 2,092
  • 3
  • 22
  • 52
1
vote
1 answer

Matlab exp only works on the first element?

I've been trying to get a simple sigmoid function to work in matlab and it seems it only works for the first element of the matrix. my code is: function g = sigmoid(z) g = zeros(size(z)); g = 1/(1 + exp(-z)); end Now it works fine for…
1
vote
1 answer

randomized element-wise multiplication in R

I've been digging around the site for an answer to my question, and I'm new with R so I'm hoping this is even possible. I have two large matrices of simulations (A = 100,000 x 50 and B = 10,000 x 50) that I would like to randomly multiply…
Shmoose
  • 13
  • 2
1
vote
1 answer

Matlab element-wise power - can't understand how it works

I have a matched filter, which I want to plot its frequency response in Matlab. The filter response is: H(f) = I tried to to plot it with: %Freqency_Response_of_wiener_filter f = linspace(-1e3,1e3,1e5); H =…
Bak Itzik
  • 466
  • 1
  • 5
  • 17
1
vote
2 answers

Python: Element wise division operator error

I would like to know is there any better way to perform element wise division operator in python. The code below suppose to perform division A1 with B1 row and A2 with B2 rows therefore my expected output is only two rows. However the division part…
Xiong89
  • 767
  • 2
  • 13
  • 24
1
vote
1 answer

Python: How to perform division according to its representation?

I would like do perform division with respect to its alphabet. Given an example as below: The binary file given is in csv format: A=1000, C=0100, G=0010, T=0001 binary.csv: CAT, GAA 0,1,0,0,1,0,0,0,0,0,0,1 0,0,1,0,1,0,0,0,1,0,0,0 The binary.csv…
Xiong89
  • 767
  • 2
  • 13
  • 24
1
vote
1 answer

How to sample matrix elements in matlab

I have a list of coordinates I would like to sample from a Matrix. Is there any elegant way to do it? Ideally, something that looks like: A = magic(5) A = 17 24 1 8 15 23 5 7 14 16 4 6 13 20 …
Yuval Atzmon
  • 5,645
  • 3
  • 41
  • 74
1
vote
1 answer

In OpenCV 3.0 how to use functions like equalizeHist after elementwise operations (both python and C++)

I have performed elementwise operations on my image. (Essentially I implemented an algorithm to remove smudge marks. note that avggrad, I0avggrad, avg and I0avg are all of mat type containing floats as elements) a = avggrad/I0avggrad b = avg - I0avg…
Parth Sane
  • 13
  • 5
1
vote
1 answer

How can I perform element-wise multiplication for Ruby arrays?

courses, credits and points are Ruby arrays with an equal size. gpa = (([credits, courses, points].transpose.map {|x| x.reduce(:*)}).inject{|sum,x| sum + x }).round(2) This method prompted an error message when I was trying to run it. Error…
sponavitus
  • 35
  • 1
  • 6
1
vote
1 answer

Elementwise Subtraction(or addition) of columns from two dataframes based on the same values/matches in other columns

I have two data frames. df1 = pd.DataFrame({'Ver' : [2,2,2], 'SN' : [1,1,1], 'Split' : [AA,AA,AA] 'Quad' : [3,3,4] 'Channel' : [1,2,0] 'Mean' :…
1
vote
1 answer

Elementwise logical comparison of numpy arrays

I have two numpy arrays of the same shape. The elements in the arrays are random integers from [0,N]. I need to check which (if any) of the elements in the same position in the arrays are equal. The output I need are the positions of the same…
1
vote
2 answers

Elementwise multiplication of a matrix by a vector

Suppose I have a matrix A=rand(2,14,24) and a vector x=10*ones(1,14) I want element wise multiplication of A and x, such that B(i,j,k)=A(i,j,k)*x(j) for all j=1,2,..14. I want to be able to do this without running a loop. What is the most efficient…
skr
  • 452
  • 6
  • 21
0
votes
1 answer

Numpy arrays operations, different shapes

Suppose you have few logical tables as follows: import numpy as np table1 = np.zeros((4,3)); table2 = np.zeros((4,3)); table3 = np.zeros((4,3)); table1[0] = 1; table2[1] = 1; table3[1] = table3[3] = 1; Now suppose you have a set of arrays that…
zizou
  • 67
  • 1
  • 5
0
votes
1 answer

Adding up arrays inside optaplanner constraint

In an Optaplanner constraint, I iterate over a set of planning entities that contain an attribute which is a time series of fixed size. I want to add up all the time series and check that the sum is always below a certain threshold. In Optaplanner,…