pyCthon
pyCthon

Reputation: 12341

max of a column in a numpy array in python

In Matlab you can do things such as

Mat1[: , end] = max( Value1 * (Mat2[:, end]-Value2 ),0)

I tried the equivalent in Python but i'm getting an error and i'm not sure why

Mat1[: , -1] = max( Value1 * (Mat2[:, -1]-Value2 ),0)

The error is below

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Upvotes: 0

Views: 54

Answers (1)

zhangxaochen
zhangxaochen

Reputation: 33997

You are using the python builtin method max, use np.max instead:

import numpy as np
Mat1[: , -1] = np.max( Value1 * (Mat2[:, -1]-Value2 ),0)

Upvotes: 1

Related Questions