Python Forum
Problem Sending a Dataset to a function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem Sending a Dataset to a function
#3
Thanks Bowlofred, very instructive !

Although the two versions of k1 look similar when printed, clearly Python sees them differently.
Your suggestion solves the problem, and I am using eval to convert the string to tuple as at line 26 attached.

Thanks again, brilliantly simple.

Astrikor

import gradients
print("Part A - direct input to Trend function")
k = (2, 4,6,8)
Gradient = gradients.Trend(k)
print()
print("Gradient = ",Gradient)
print()
print("######################")
print()
print()
print("Part B - indirect input to Trend function")
print()
print("Create example data list k")
x = k = 2
while x < 8:
        x = x + 2
        k = k,x     
print("k2 = ",k)

# remove all brackets from k:
k = str(k).replace('(', '').replace(')', '')
print("k3 = ",k)
k = "({})".format(k)
print("k4 formatted to match direct newdata :   ",k)
print()
k = eval(k)#(converts string to tuple)
print("k5 Converted to tuple = ", k)
#send data to Trend function:
Gradient = gradients.Trend(k)
print()
print("Gradient = ",Gradient)
Reply


Messages In This Thread
RE: Problem Sending a Dataset to a function - by Astrikor - Jun-10-2020, 08:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem loading an image dataset into Tensorflow MohammedSohail 1 1,762 Jun-09-2020, 02:09 PM
Last Post: nuffink
  Problem in sending email using python nhoh007 1 2,554 Aug-25-2018, 07:20 PM
Last Post: typic
  Problem with sending text file as an attachment using this Gmail OAuth script downloaderfan 6 7,012 Feb-07-2018, 09:54 PM
Last Post: downloaderfan

Forum Jump:

User Panel Messages

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