Python Forum
How to sum elements of same position in n dimensional array
Thread Rating:
  • 4 Vote(s) - 3.25 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to sum elements of same position in n dimensional array
#1
Hi, guys,

I have a numpy array of (2,100,2) dimensions, that I want to sum elements of the same position. In order to clarify my doubts, I wrote the example below where I substituted the numbers by letters with dimensions (2,2,2): 

[[[a b]
  [c d]]
 [[a b]
  [c d]]]
So, I look for a way to sum a+a, b+b, c+c, d+d, and obtain an array with dimensions (2,2,1). Here's the desired output:

[[a+a  b+b]
 [c+c  d+d]]
I'd like something that I can extrapolate to cases with dimensions (2,100,X), where X can be numbers from 2 to 10.
Thanks !!!
Reply


Messages In This Thread
How to sum elements of same position in n dimensional array - by Felipe - May-11-2017, 12:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Formula with elements of list - If-condition regarding the lists elements lewielewis 2 2,838 May-08-2020, 01:41 PM
Last Post: nnk
  define certain array elements+display with digits lukezo 0 1,287 Apr-10-2020, 05:03 PM
Last Post: lukezo
  How to prepare a NumPy array which include float type array elements subhash 0 1,958 Mar-02-2020, 06:46 AM
Last Post: subhash
  How convert multidimensional array to two dimensional array tkkhan44 1 2,834 Feb-20-2019, 05:00 AM
Last Post: scidam
  How to add an element such as an average to a multi-dimensional array? xhughesey 6 4,111 Jan-06-2019, 10:47 PM
Last Post: xhughesey
  Checking the elements of a matrix with an elements of a list juniorcoder 11 6,032 Sep-17-2018, 03:02 PM
Last Post: gruntfutuk
  Three-dimensional Contour Plots minifizikus 1 3,321 Sep-13-2018, 10:56 PM
Last Post: Larz60+
  2 Dimensional NumPy for beginners Jack_Sparrow 2 3,154 May-08-2018, 05:21 PM
Last Post: killerrex
  Recurse through n-dimensional array ColdDeath 2 3,025 Apr-05-2018, 11:20 AM
Last Post: KenniT
  Two Dimensional Chart from CSV File srini1995 0 2,263 Nov-27-2017, 07:10 AM
Last Post: srini1995

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020