Questions tagged [elementwise-operations]

204 questions
3
votes
2 answers

Multiply elements of a matrix with vector values

I have a matrix M, I want to create 3 additional matrices where each additional matrix has certain 3x3 column-slices of M multiplied by values in a vector, I will then store the resulting 3 new matrices in a list. ##create the initial matrix M <-…
flee
  • 1,253
  • 3
  • 17
  • 34
3
votes
3 answers

How to apply one argument to Array{Function, 1} element-wise smartly in Julia?

I understand Julia can apply element-wise argument to a function by f.(x) in v0.6 x = [1, 2, 3] f = x->3x @assert f.(x) = [3, 6, 9] Now, I define f as Array{Function, 1}. f1(x) = 3x f2(x) = 4x f = [f1, f2] x = 2 @assert isa(f, Array{Function,1})…
Hiroaki
  • 47
  • 4
3
votes
2 answers

Creating an array in Swift by applying binary operation to all elements of two other arrays

Is there a concise way in Swift of creating an array by applying a binary operation on the elements of two other arrays? For example: let a = [1, 2, 3] let b = [4, 5, 6] let c = (0..<3).map{a[$0]+b[$0]} // c = [5, 7, 9]
Danra
  • 9,546
  • 5
  • 59
  • 117
3
votes
1 answer

Numpy element-wise in operation

Suppose I have a column vector y with length n, and I have a matrix X of size n*m. I want to check for each element i in y, whether the element is in the corresponding row in X. What is the most efficient way of doing this? For example: y =…
3
votes
2 answers

How to efficiently construct a matrix in matlab that depends on indices

In my program in matlab I have several instances where I need to create a matrix, which entries depends on its indices and perform matrix-vector operations with it. I wonder how I can implement this most efficiently. For example, I need to speed…
3
votes
0 answers

Python: How to divide row values in csv file with respect to assigned specific values?

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
3
votes
2 answers

Apply function to each row in Torch

I know that tensors have an apply method, but this only applies a function to each element. Is there an elegant way to do row-wise operations? For example, can I multiply each row by a different value? Say A = 1 2 3 4 5 6 7 8 9 and B = 1 …
Veech
  • 1,397
  • 2
  • 12
  • 20
2
votes
1 answer

Elementwise substraction in Julia

I am comming to julia from MATLAB and find myself startled at the idea that there isnt a better way to solve this: 1-[.5 .2 1] in julia does not compute to [0.5 0.8 0] 1-[.5 .2 1] MATLAB-> [0.5 0.8 0] While in julia the best I got is: -(-[.5 .2…
Orlando
  • 23
  • 3
2
votes
3 answers

Can jq add objects in two JSON object lists sequentially?

I am seeking the simultaneous iteration of two lists. Input object list: First Input Object List { "k11": "v111", "k12": "v112" } { "k11": "v121", "k12": "v122" } { "k11": "v131", "k12": "v132" } Second Input Object List { "k21":…
Paul
  • 442
  • 4
  • 9
2
votes
0 answers

Numpy: Why is elementwise binary operation much slower when applied to matrixes with inconsistent memory layout and sizes being big powers of 2?

I have been experimenting with performance of operation in Numpy and it turns out that performing element-wise operation (for example np.multiply) on matrices with inconsistent memory layout (one with order 'C' and second 'F') is around 2 times…
krzysztor
  • 21
  • 5
2
votes
2 answers

Matrix multiplication with vector based on another matrix in R

I need to multiply one matrix with one conditional vector, to get a vector of solutions, based on another matrix. # Matrix A lsA <- c(1,1,0,1,1,2,1,0,1,2,1,1,0,0,1,1,0,0,0,1) A <- matrix(lsA,4,5, byrow = T) # Matrix B ls <-…
ana_gg
  • 370
  • 1
  • 9
2
votes
2 answers

elementwise comparison in ndarray::Array1 in rust

I'm trying to find the rust equivalent of this python numpy code doing elementwise comparison of an array. import numpy as np np.arange(3) > 1 Here's my rust code: use ndarray::Array1; fn main() { let arr = Array1::::range(0.0, 3.0, 1.0); …
Chad
  • 1,434
  • 1
  • 15
  • 30
2
votes
1 answer

Pandas: Element-wise sum-product of data frame of values using a another data frame containing row weights

Hopefully, this is not a duplicate. I have two data frames: The first data frame has size n x m, and each cell contains a list of numeric values of size k. The second data frame has size n x k, and each cell contains a single numeric value…
2
votes
2 answers

Element-wise operation with lambda (pd.DataFrame)

Trying to subtract a constant array from a DatraFrame using lambda. This is my DataFrame d: import pandas as pd d = pd.DataFrame() d['x'] = pd.Series([1, 2, 3, 4, 5, 6]) d['y'] = pd.Series([11, 22, 33, 44, 55, 66]) A working as expected classical…
Lourenco
  • 2,772
  • 2
  • 15
  • 21
2
votes
3 answers

Java Element-wise merge of two list

I have two List of int like {1,2,3} and {4,5,6}. I need to obtain a List> like: ((1,4),(2,5),(3,6)) How should i proceed? I tried with for but i can get only the cartesian product
pierbin24
  • 31
  • 5