Python Forum
creating functions which modify numpy array
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
creating functions which modify numpy array
#1
Hello,

I'm a physic student and I am working on a simulation and I have some weird results. I wonder if my errors didn't come from my misunderstanding of basics. For this work I need to create two functions : the first one to create an array using global variable (which are not array) and the second one to modify an array which already exist using the array created by the first function. I knows that there is some subtility with this tye of functions but I don't know them. Let's start with the firts one.


P.S :I cannot post all the code because if they see my code somewhere else they could accuse me of plagiarism and I don't want any problem. So I will just put '######' to replace parts of the code which I'm sure are correct.

Import numpy as np
def f1(l):                          # l is used in the program as an idex for the array B defined at the begining of my code. D is also an array
    q=(h/B[l])*D                    # h is a float defined at the begining of my code
    e=q[0]/(B[l])
    A=np.diag(e)
    for i in range(0,n):            # n,m int defined at the begining of my code
        ################            # part of the code wich inject q in A
    return A
Now the second function which takes an existing array F and and int u.


def f2(F,u):
    for i in range(1,J):              #J int defined at the begining of the code
        F[:,u]=f1(i)@F[:,u]@F[:,u-1]
    return F
I need F[:,u] to be modified and F[:,u-1] to be non-modified. Then I used


for u in x:    #x an array of int defined at the begining of my code
    f2(F,u) 
So I use the two functions to modify some columns of F. Is the structure of my code problematic ?

Thanks for your help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Self taught , (creating a quiz) syntax error on my array DarkAlchemyXEX 9 4,261 Jan-10-2020, 02:30 AM
Last Post: ichabod801
  Numpy array delete cells LB_994 1 2,223 Nov-19-2018, 09:20 AM
Last Post: ThiefOfTime
  creating functions - make optional argument a reversal anstuteville 2 2,596 Aug-31-2018, 02:36 PM
Last Post: anstuteville
  User input numpy array with color mapping & mouse click events imakeathepi 0 3,328 Aug-15-2017, 10:33 AM
Last Post: imakeathepi
  reshaping numpy array ValueError: total size of new array must be unchanged metalray 0 5,911 Jul-15-2017, 05:41 PM
Last Post: metalray

Forum Jump:

User Panel Messages

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