Isn't there a sumif, countif function like Excel in the Numpy array?

Asked 2 years ago, Updated 2 years ago, 119 views

I am looking for sumif, countif functions like calculating the python3 array Excel.

If you know this, please give us your advice.

python python3 numpy array

2022-09-30 18:16

1 Answers

If you use boolean array indexing to specify subscripts using a conditional expression,

# numpy array for testing
arr = numpy.array(list(range(10))))
# output sumif
print(arr[arr>5].sum())
# Output countif
print(numpy.sum(arr>5))

You can write as shown in

--Metropolis's Commentsfrom


2022-09-30 18:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.