Thanks!. very useful. although doesn't really work with padded array (as in the case of real_map object). but found my way round.

best
mona
On Oct 18, 2011, at 11:17 AM, Ralf Grosse-Kunstleve wrote:

Hi Mona,

Try this:

from scitbx.array_family import flex
a=flex.double([1,4,5,7,5,6,6,1])
a.set_selected(a > 5, 5)
print list(a)

Or in smaller steps:

bool_selection = a > 5
assert bool_selection.size() == a.size()
print list(bool_selection)
a.set_selected(bool_selection, 5)
print list(a)

You can also call a.set_selected(bool_selection, b)
where b is an array with as many elements as you have True in the bool_selection.

This kind of working with selections is very typical within cctbx/phenix.
If you look through our sources you'll find a lot of examples; in passing, we have two types of selections, bool selections as above, and integer selections. The latter are useful for permutations, e.g. to sort array elements, or if you know you select only a small number of elements from a large array. Let me know if you have more questions about selections and I'll be happy to explain. (I guess one day I should write a "Working with selections" tutorial.)

Ralf

On Tue, Oct 18, 2011 at 2:54 AM, Monarin Uervirojnangkoorn <[email protected]> wrote:
Hi,

I'm using flex and 'd like to get an access to elements fall beyond/ below certain value. eg.
a=[1,4,5,7,5,6,6,1]
anything beyond 5 should be set to 5. (in matlab then a(a>5)=5;)
if you could tell me how to do this quickly for flex, that would be great. for now i use loop and that is... pretty slow.

many thanks.
mona



^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^
Institute of Biochemistry,
Institut f�r Neuro- und Bioinformatik,
Graduate School for Computing in Medicine and Life Sciences
University of L�beck,
Ratzeburger Allee 160
L�beck 23538
Germany
Tel: +49451-5004072
Fax: +49451-5004068





_______________________________________________
cctbxbb mailing list
[email protected]
http://phenix-online.org/mailman/listinfo/cctbxbb


_______________________________________________
cctbxbb mailing list
[email protected]
http://phenix-online.org/mailman/listinfo/cctbxbb

^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^
Institute of Biochemistry,
Institut f�r Neuro- und Bioinformatik,
Graduate School for Computing in Medicine and Life Sciences
University of L�beck,
Ratzeburger Allee 160
L�beck 23538
Germany
Tel: +49451-5004072
Fax: +49451-5004068