I'd like to know if it's possible to apply a function (or juste an operation, such as replacing values) to column in a python 2d array, without using for loops.
I'm sorry if the question has already been asked, but I couldn't find anything specific about my problem.
I'd like to do something like :
array[:][2] = 1
Which would mean put 1 for each value at the third column, or
func(array[:][2])
Which would mean apply func()
to the third column of array.
Is there any magic python-way to do it ?
EDIT : The truth has been spoken. I forgot to say that I didn't want to avoid for()
statement to improve performance, but just because I don't wan to add multiples lines for this precise instance. We got 2 answers here, one in a native way, and two more with the help of Numpy. Thanks a lot for your answers !