Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Element wise computation
#3
(Apr-29-2022, 08:09 AM)Gribouillis Wrote: I would try something like this:

import numpy as np
import math as mt

G = np.array([[1, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 0, 0, 0, 0], [1, 1, 1, 1, 0, 0, 0, 0], [1, 0, 0, 0, 1, 0, 0, 0], [1, 1, 0, 0, 1, 1, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1]])
 
r = np.array([-56.53511658, -96.6740462, -85.23212419, -90.05029513, -86.19336384, -79.31883055, -67.7323369, -86.49784743])

def main():
    s = r.reshape((1, len(r)))
    print(s)
    M = G * s.T
    print(M)
    tmp = np.tanh(M*0.5)
    print(tmp)
    p = np.prod(tmp, axis=0)
    print(p)
    print(2 * np.arctanh(p))

if __name__ == '__main__':
    main()
The numerical result is deceiving however, due to the large values in the array r
Output:
[[-56.53511658 -96.6740462 -85.23212419 -90.05029513 -86.19336384 -79.31883055 -67.7323369 -86.49784743]] paillasse/pf/numbox.py:17: RuntimeWarning: divide by zero encountered in arctanh [[-56.53511658 -0. -0. -0. -0. -0. -0. -0. ] [-96.6740462 -96.6740462 -0. -0. -0. -0. -0. -0. ] print(2 * np.arctanh(p)) [-85.23212419 -0. -85.23212419 -0. -0. -0. -0. -0. ] [-90.05029513 -90.05029513 -90.05029513 -90.05029513 -0. -0. -0. -0. ] [-86.19336384 -0. -0. -0. -86.19336384 -0. -0. -0. ] [-79.31883055 -79.31883055 -0. -0. -79.31883055 -79.31883055 -0. -0. ] [-67.7323369 -0. -67.7323369 -0. -67.7323369 -0. -67.7323369 -0. ] [-86.49784743 -86.49784743 -86.49784743 -86.49784743 -86.49784743 -86.49784743 -86.49784743 -86.49784743]] [[-1. -0. -0. -0. -0. -0. -0. -0.] [-1. -1. -0. -0. -0. -0. -0. -0.] [-1. -0. -1. -0. -0. -0. -0. -0.] [-1. -1. -1. -1. -0. -0. -0. -0.] [-1. -0. -0. -0. -1. -0. -0. -0.] [-1. -1. -0. -0. -1. -1. -0. -0.] [-1. -0. -1. -0. -1. -0. -1. -0.] [-1. -1. -1. -1. -1. -1. -1. -1.]] [1. 0. 0. 0. 0. 0. 0. 0.] [inf 0. 0. 0. 0. 0. 0. 0.]
Note that the boxplus operator returns 0 as soon as one of the arguments is 0, and the matrix G contains many zeroes.

Thank you very much for your help, @Gribouillis. It gives me a new perspective on the problem. And please forgive me for being so late in replying to your post.
Reply


Messages In This Thread
Element wise computation - by divon - Apr-26-2022, 12:20 PM
RE: Element wise computation - by Gribouillis - Apr-29-2022, 08:09 AM
RE: Element wise computation - by divon - Jun-01-2022, 02:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  numpy.dot() result different with classic computation for large-size arrays geekgeek 5 1,950 Jan-25-2022, 09:45 PM
Last Post: Gribouillis
  How do I read in a Formula in Excel and convert it to do the computation in Python? JaneTan 2 2,705 Jul-07-2021, 02:06 PM
Last Post: Marbelous
  Appropriate data-structure / design for business-day relations (week/month-wise) sx999 2 2,838 Apr-23-2021, 08:09 AM
Last Post: sx999
  5 python columns, row-wise as input to a function dervast 1 2,051 Jul-17-2019, 08:53 PM
Last Post: Larz60+
  Inserting a python list into a dataframe column wise mahmoud899 0 4,302 Mar-04-2019, 11:44 PM
Last Post: mahmoud899
  Unable to locate element no such element gahhon 6 4,560 Feb-18-2019, 02:09 PM
Last Post: gahhon
  how to program robot to pass wise man puzzle steven12341234 0 1,973 Dec-02-2018, 08:31 AM
Last Post: steven12341234
  Change single element in 2D list changes every 1D element AceScottie 9 12,151 Nov-13-2017, 07:05 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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