Questions tagged [elementwise-operations]

204 questions
0
votes
4 answers

Apply condition in for loop to each element in a list of lists

I am trying to see if each value in array is less then 0 then output 0, else output the number itself. The output must have the same dimensions as the input. Currently the input is a 3 by 4 but output is a list. How do I get the output size the same…
maximus
  • 335
  • 2
  • 16
0
votes
5 answers

Concatenate the nested arrays within a single 2d array, element-wise

I have a numpy array like this: array = [[1, 3, 5, 7], [2, 4, 6, 8]] I would like to concatenate them element-wise. Most of the solutions I have found are able to do this with two separate 2d arrays, but I would like to do this within a single 2d…
0
votes
1 answer

Element wise multiplication of decision variable array and list of integers in python RSOME

I have a decision variable array and I want to multiply each decision variable with a different integer of a list Here is an example: #Import libraries from rsome import ro m=3 a = [0.10,0.1,1] b = [0.13,0.1,0.3] #create a model object model =…
0
votes
1 answer

Element-wise multiply of multiple numpy 2d arrays

To simplify my question, let's say I have these arrays: a = np.array([[1, 2, 3], [4, 5, 6]]) b = np.array([[2, 2, 2], [3, 3, 3]]) c = np.array([[1, 1, 3], [4, 1, 6]]) I would like to use element-wise multiplication on them so the result will…
0
votes
1 answer

How can i do elementwise multiplication of more than 3 multidimensional arrays without using loop

I have a 3-dimensional array which contains four 2-dimensional arrays >>> print(newimagetensor) # printing the array [[[1.06340611e+02 1.83682746e+02 2.91655784e-02 7.70948060e+01] [3.74227522e+01 2.35463417e+01 4.74963539e+01 8.81179854e+01] …
Ryan
  • 33
  • 1
  • 6
0
votes
2 answers

Element-wise division on sparse matrix python

I have a sparse matrix of size (n x m): sparse_dtm = dok_matrix((num_documents, vocabulary_size), dtype=np.float32) for doc_index, document in enumerate(data): document_counter = Counter(document) for word in…
Emil
  • 1,531
  • 3
  • 22
  • 47
0
votes
1 answer

Name-Specific Variability Calculations Pandas

I'm trying to calculate variability statistics from two df's - one with current data and one df with average data for the month. Suppose I have a df "DF1" that looks like this: Name year month output 0 A 1991 1 10864.8 1 A …
user2100039
  • 1,280
  • 2
  • 16
  • 31
0
votes
2 answers

I basically want to do an element-wise addition but using only for loops, so no numpy or map

Here's what I want the layout to look. I want it to be a function so I can use it in the cmd prompt. The lengths of each list have to be the same, if not it should return none def add_elements(list1, list2): if len(list1)==len(list2): …
0
votes
2 answers

Element wise multiplication of iterators and calculating sum

Using two Lists, element wise multiplication of these lists and sum of resultant list can be calculated in following way. (List1 , List2).zipped.foldLeft(0.0) { case (a, (b, c)) => a + b * c } How can I preform this operation for two iterators in…
Asif
  • 763
  • 8
  • 18
0
votes
1 answer

Why is numpy not faster for comparing element-wise greater values in two arrays?

I have three versions of the functions to do element-wise comparison of two lists and output a count of results. First uses for loop (simple function), second uses list expression, third uses numpy. I expected numpy to be super-fast especially once…
rbewoor
  • 305
  • 1
  • 3
  • 14
0
votes
1 answer

MonogDB document structure: Map vs. Array for element-wise aggregations

We want to store ratings of a metric (say sales, profit) for some category (say city) in MondoDB. Example rating scale: [RED, YELLOW, GREEN], the length will be fixed. We are considering the following two document structures: Structure 1: Ratings as…
racerX
  • 930
  • 9
  • 25
0
votes
1 answer

Element-wise logical auto-combination of pandas boolean series

s = pandas.Series([True,False,True,True,False]) len(s)==5 while len(s[:-1]) == len(s[1:]) = 4, the element-wise AND combination len(s[1:] & s[:-1]) = 5, even len(s[1:].copy() & s[:-1].copy()) = 5 environment is python3.6 on Jupyter, pandas 0.21.0
0
votes
1 answer

element wise multiplication of 2D tensors as layer of neural network in pytorch

I have a 3D torch tensor with dimension of [Batch_size, n, n] which is the out put of a layer of my network and a constant 2D torch tensor with size of [n, n]. How can I perform element wise multiplication over the batch size which should resulted…
user1538653
  • 121
  • 1
  • 1
  • 10
0
votes
0 answers

Broadcasting mulitplication/division with sparse matrix in Octave

In Octave, one can do an element-wise multiplication between a full matrix and compatible (broadcastable) vector (i.e. MxN .* 1xN or MxN .* Mx1). But this does not seem to be applicable for sparse matrix. Consider the following example, v =…
codechimp
  • 1,509
  • 1
  • 14
  • 21
0
votes
4 answers

element wise checking of nested list

Check nested list elementwise for multiple conditions and return 0 or 1 if condition is not met or is met. I have to check at least 14 cannot be equal to= 19 if the element ends in 4 or 9 For example, age array of [[22, 13, 31, 13], [17, 14, 24,…
zelda26
  • 489
  • 2
  • 10
  • 33