Questions tagged [elementwise-operations]

204 questions
-1
votes
1 answer

How to iterate a list of dictionaries and perform elementwise calculations with entries

I am trying to multiply entries of a list of dictionaries, see the example code below. It generates TypeError: list indices must be integers or slices, not dict How can this kind of operation be achieved? list_of_uscases = [ { "uscase": 1, "power":…
MacUserXL
  • 35
  • 5
-1
votes
1 answer

How to do dot products elementwise in numpy

Does anyone know of a way to do an elementwise dot product with numpy? import numpy as np a = np.array([ [0,0,0],[0,0,1] ]) b = np.array([ [1,2,3],[1,3,2] ]) for i in range(0, size(a)): c.append(np.dot(a[i],b[i])) and I want c = [0,2] Also how…
-1
votes
1 answer

Element-wise comparison of numpy arrays of different lengths

I would like to compare numpy arrays of equal size in terms of greater/smaller relations. Specifically, I have >>> import numpy as np >>> A = np.array([0.5, 2., 0.1, 12.]) >>> B = np.ones(len(A)) >>> A
-2
votes
1 answer

Element-wise addition of lists nested in two dictionaries (Python)

I have two dictionaries, and the value for every key is a list of two elements, something like this: dict1 = {1234: [40.26, 4.87], 13564 [30.24, 41.74], 523545 [810.13, 237.94]} dict2 = {1231: [43.26, 8.87], 13564 [904.71, 51.81], 52234 [811.13,…
-2
votes
1 answer

Octave error: horizontal dimensions mismatch - matrix elementwise matlab

k = linspace(0,0.5)' h = 6.58212 * 10^-16 m_0 = 9.109383 * 10^-31 E_c = ( h^2 * k.^2 ) / ( 10^-5 * m_0 ) A = [E_c, 1, 2; 3, 4, 5; 6, 7, 8] When I run this code, I get: error: horizontal dimensions mismatch (100x1 vs 1x1) error: called from …
Joel
  • 665
  • 2
  • 9
  • 23
-2
votes
2 answers

ValueError when defining a lambda function in python

I am receiving a ValueError when using integration, but I cannot understand why. Here is my simplified code: import numpy as np import scipy.integrate as integrate pbar = 1 p = np.arange(0,pbar,pbar/1000) h = lambda p: p**2/2+p*(1-p) Kl = lambda p:…
splinter
  • 3,727
  • 8
  • 37
  • 82
-3
votes
4 answers

Python : Vectorized comparison of two ordered numpy arrays of int of the same size

I want to compare two ordered numpy arrays of int of the same size in Python and output the common elements which are the same value at the same position : import numpy as np a = np.asarray([20, 35, 226, 62, 129, 108, 156, 225, 115, 35, 162, 43, 9,…
SebMa
  • 4,037
  • 29
  • 39
-4
votes
2 answers

element-wise comparison, matlab vs python numpy

I'm a Matlab user and I'm learning Python. I want to create new arrays with element-wise comparison. Using Matlab: In the example I have solar radiation, temperature and relative…
scana
  • 111
  • 1
  • 11
-4
votes
1 answer

Elementwise Power in IT++

I was wondering if it was possible to do element wise power in it++. I have not seen a builtin function, and if I overlooked it. How can I achieve this?
Carnez Davis
  • 863
  • 2
  • 8
  • 12
1 2 3
13
14