I have the following code:
print(img.size) print(10 * img.size)
This will print:
(70, 70) (70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70)
I'd like it to print:
(700, 700)
Is there any way to do this without having to write:
print(10 * img.size[0], 10 * img.size[1])
PS: img.size
is a PIL image. I don't know if that matters anything in this case.
Concatenating and Multiplying Tuples Concatenation is done with the + operator, and multiplication is done with the * operator. Because the + operator can concatenate, it can be used to combine tuples to form a new tuple, though it cannot modify an existing tuple. The * operator can be used to multiply tuples.
In order to multiply array by scalar in python, you can use np. multiply() method.
Tuple Indexing We can access elements in a tuple in the same way as we do in lists and strings. Hence, we can access elements simply by indexing and slicing.
When it is required to concatenate multiple tuples, the '+' operator can be used. A tuple is an immutable data type. It means, values once defined can't be changed by accessing their index elements. If we try to change the elements, it results in an error.
Might be a nicer way, but this should work
tuple([10*x for x in img.size])
img.size = tuple(i * 10 for i in img.size)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With