0

How to select max when comparing single element & array in python?

ex: i = 5 & a = np.array([3,9,1,4,6])

expected result is an array = [5,9,5,5,6]

by comparing i to each element of a & select the max.

Besides use for loop, is there a vectorization faster way?

2

1 Answer 1

2

What you are looking for is numpy.maximum:

import numpy as np

i = 5
a = np.array([3,9,1,4,6])

print(np.maximum(i,a))
# [5,9,5,5,6]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.