About 1,190,000 results
Open links in new tab
  1. Python | Tuple multiplication - GeeksforGeeks

    Apr 23, 2023 · Define a list comprehension [x * y for x, y in zip(test_tup1, test_tup2)] that iterates through both tuples in parallel using the zip function, multiplies the corresponding elements of …

  2. Python | Multiply elements of Tuple - GeeksforGeeks

    Feb 21, 2023 · Define a lambda function to multiply the elements of a tuple. Apply the lambda function to each tuple in the input list using reduce() function and append the result to the …

  3. How to Multiply all items in TuplePython | GeeksforGeeks

    Feb 11, 2025 · reduce () function from functools applies a function cumulatively to the elements of an iterable, making it useful for multiplying all elements in a tuple. Explanation: reduce (lambda …

  4. python - Get the (multiplicative) product of a tuple or list?

    In short, just use np.prod. import numpy as np my_tuple = (2, 3, 10) print(np.prod(my_tuple)) # 60 Which is in your use case. np.sum(np.prod(x) for x in combinations(args, 2)) np.prod can take …

  5. python - Multiplying a tuple by a scalar - Stack Overflow

    You are trying to apply the function on Tuple as a whole. You need to apply it on individual elements and return a new tuple. newTuple = tuple([10*x for x in oldTuple])

  6. python - Elegant way to perform tuple arithmetic - Stack Overflow

    Jul 2, 2013 · What is the most elegant and concise way (without creating my own class with operator overloading) to perform tuple arithmetic in Python 2.7? Lets say I have two tuples: a = …

  7. How to multiply the Elements of a Tuple in Python | bobbyhadz

    Apr 9, 2024 · To multiply the elements of a tuple by a number: Use a generator expression to iterate over the tuple. Multiply each tuple element by a number. Use the tuple() class to …

  8. Multiply All Items in a Tuple in Python - Online Tutorials Library

    Jul 18, 2023 · We can multiply all the items in a tuple using various methods like using a for loop, using the reduce() function from the functools module, using list comprehension, and the …

  9. How to Multiply Elements in Python Tuples | Tutorial Reference

    This guide explores how to perform multiplication operations on elements within Python tuples. We'll cover multiplying all elements of a tuple together, multiplying tuple elements by a …

  10. Mastering Tuple Multiplication in Python: A Comprehensive Guide

    In this article, we’ll explore how to multiply elements of a tuple in various ways, including using scalar, math.prod (), reduce () function, list comprehension, and a for loop. Suppose you have …

Refresh