Numpy slicing problem Zero01 Seasoned Gimper    Posts: 101 Threads: 11 Joined: Apr 2017 Reputation: 3 Operating system(s): Windows (Vista and later) Linux Gimp version: 2.8 07-18-2021, 04:21 PM (This post was last modified: 07-18-2021, 06:04 PM by Zero01. Edit Reason: typo's etc ) Code: ```import numpy as np a  = np.concatenate((np.linspace(10,200,25),np.geomspace(200,360,25))) b  = np.concatenate((np.linspace(20,-180,25),np.linspace(-180,230,25))) c = a+(b)/np.pi if c >= 360:    c = 360 d= a+(b)/np.pi if d >= 360:    d = 360 e = np.linspace(c,d,50) f = open("new.txt","w") for i in range(50):    f.write("gmic someFilter params: "+str(a[i])+","+str(b[i])+","+str(e[i])+" -o somefiles%04d.file \n" % i) f.close()``` Tryin to get it so that in all 50 outputs to the text file, the value of 'e' is: a + b / pi (or 360 if e >= 360). First output seems ok i.e.: gmic someFilter params: 10.0,20.0,16.366197723675814 -o somefiles0000.file but subsequent values are messed up, i.e. the last one: gmic someFilter params: 360.0,230.0,32.15845056908105 -o somefiles0049.file .. the value of 'e' in this case should be about 82, not 32.. My slicing is probably the issue as I've no experience doing this, any help gratefully received. cheers! Zero01 Seasoned Gimper    Posts: 101 Threads: 11 Joined: Apr 2017 Reputation: 3 Operating system(s): Windows (Vista and later) Linux Gimp version: 2.8 07-18-2021, 06:38 PM EDIT: '.. the value of 'e' in this case should be about 187, not 32..' Ofnuts Administrator       Posts: 4,238 Threads: 190 Joined: Oct 2016 Reputation: 310 Operating system(s): Linux Gimp version: 2.10 07-18-2021, 08:02 PM Strange way to use numpy. The whole point of numpy is do add vectors in one operation, so you can compute an intermediate vector that holds your c and d values using; Code: ```# The vector of the sums: a+b # The vector of the sum, clamped at 360: np.minimum(a+b,360) # The vector of the sums, clamped and in radians result=np.minimum(a+b,360)/np.pi``` The strange thing in your code is that when you do Code: `c = a+(b)/np.pi` Only the b part is divided by np.pi, which looks odd, and the parentheses around the (b) don't serve any purpose. So I assume you meant: Code: `c = (a+b)/np.pi` Since you have values up to 360, I assume you are trying to cover a full circle so, you may want to divide by 2*np.pi if you really want a value in radians, because a full circle is 2×π Then I don't really understand what you do with e (linear sample between two values with an interval of 4?)? And what happens when i>=7? Zero01 Seasoned Gimper    Posts: 101 Threads: 11 Joined: Apr 2017 Reputation: 3 Operating system(s): Windows (Vista and later) Linux Gimp version: 2.8 07-19-2021, 07:31 AM (This post was last modified: 07-19-2021, 07:45 AM by Zero01. Edit Reason: typos ) Pi is a red-herring here I'm afraid!! It's an arbitrary value, I could have divided by 5 or 10 or anythibg but chose pi for no particular reason... Well, I managed to get somewhere with my code, thanks for your help..  I used np.clip in the end to help acheive the results I desired. (Even though in the example given, no values of e are over 360, I checked with different array parameters and the code I used (below) clamps the result to 360 or below.) Thanks again Ofnuts !! Code: ```import numpy as np a  = np.concatenate((np.linspace(13.76,239.04,100),np.geomspace(239.04,360,100))) b  = np.concatenate((np.linspace(20.16,-184.32,100),np.linspace(-184.32,229.68,100))) e = np.clip((np.linspace(a+b,a[-1]+b[-1],200)/np.pi),-360,360) f = open("newl.txt","w") for i in range(200):    f.write("gmic v -99 rund.png mercator "+str(a[i])+","+str(b[i])+","+str(e[i])+",0,85 resize 1280,720 normalize 0,255 o merc_%04d.png \n" % i) f.close()``` « Next Oldest | Next Newest » 