Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function with array input
#3
Something like this?
import random

def calc(variables, params):
    '''return sum of params[i] * variables[i]'''
    result = 0
    for x, y in zip(params, variables):
        result += x * y
    return result

params= [1, 1, 2, 3, 5, 8]
print(calc([1]*6), params) # Should print 20
values = [random.sample(range(100), 6) for _ in range(100)]
results = [calc(value, params) for value in values]
Reply


Messages In This Thread
Function with array input - by Gerkamspiano - Nov-30-2020, 02:03 PM
RE: Function with array input - by DPaul - Nov-30-2020, 04:14 PM
RE: Function with array input - by deanhystad - Nov-30-2020, 05:13 PM
RE: Function with array input - by Gerkamspiano - Dec-01-2020, 08:46 AM
RE: Function with array input - by ndc85430 - Nov-30-2020, 05:23 PM
RE: Function with array input - by Gerkamspiano - Dec-01-2020, 08:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Input function oldschool 1 822 Sep-14-2024, 01:02 PM
Last Post: deanhystad
  ValueError: could not broadcast input array from shape makingwithheld 1 3,131 Jul-06-2024, 03:02 PM
Last Post: paul18fr
  difference between forms of input a list to function akbarza 6 2,563 Feb-21-2024, 08:02 PM
Last Post: bterwijn
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 2,479 Dec-25-2022, 03:00 PM
Last Post: askfriends
  Showing an empty chart, then input data via function kgall89 0 1,541 Jun-02-2022, 01:53 AM
Last Post: kgall89
Question Change elements of array based on position of input data Cola_Reb 6 3,590 May-13-2022, 12:57 PM
Last Post: Cola_Reb
  input function question barryjo 12 4,745 Jan-18-2022, 12:11 AM
Last Post: barryjo
  function with 'self' input parameter errors out with and without 'self' called dford 12 8,558 Jan-15-2022, 06:07 PM
Last Post: deanhystad
  Problem with input after function luilong 10 6,325 Dec-04-2021, 12:16 AM
Last Post: luilong
  Exit function from nested function based on user input Turtle 5 4,726 Oct-10-2021, 12:55 AM
Last Post: Turtle

Forum Jump:

User Panel Messages

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