### Compare individual entries of two array and update greater number for the next iteration

144
views
0
9 months ago by
Hi, I want to compare individual entries of the solution arrays (previous and current solution) and retain the maximum of those two for each node.
For example:
Anew = [  2.20981931e-03   3.42597919e-03   3.76302946e-03 ...,   1.93586590e-04
3.06696611e-05   2.97170764e-05]​
Anew.vector().array().max() = 0.769139961146

Aold = [  2.17855850e-03   3.38654686e-03   3.72550511e-03 ...,   1.92609340e-04
2.94703464e-05   2.85539502e-05]

Aold.vector().array().max() = 0.985263255478

# I have compared like this
History = conditional(gt(Anew,Aold), Anew, Aold)

# with this I am getting a wrong answer.
# Question is whether conditional will perform the check on every entry?

​
Community: FEniCS Project

3
9 months ago by
Just do this :

from fenics import *
import numpy as np

x = np.array([3.0, 0.0, 1.0])
y = np.array([1.0, 0.0, 2.0])
z = np.maximum(x,y)

mesh = UnitIntervalMesh(2)
Q    = FunctionSpace(mesh, 'CG', 1)
f    = Function(Q)

f.vector().set_local(z)

print f.vector().array()​