questions anon wrote:

> I have been going round in circles trying to solve something that sounds
> simple. I have a huge array and I would like to reclassify the values.
> Firstly just make them zeros and ones, for example if the values in the
> array are less than 100 make them 0 and if greater than 100 make them 1.
> And then finally sum them together.
> I have attempted a few methods, see code below. Any feedback will be
> greatly appreciated.

>>> import numpy
>>> all_FFDI = numpy.arange(60).reshape((3,4,5))
>>> all_FFDI
array([[[ 0,  1,  2,  3,  4],
        [ 5,  6,  7,  8,  9],
        [10, 11, 12, 13, 14],
        [15, 16, 17, 18, 19]],

       [[20, 21, 22, 23, 24],
        [25, 26, 27, 28, 29],
        [30, 31, 32, 33, 34],
        [35, 36, 37, 38, 39]],

       [[40, 41, 42, 43, 44],
        [45, 46, 47, 48, 49],
        [50, 51, 52, 53, 54],
        [55, 56, 57, 58, 59]]])
>>> all_FFDI >= 25
array([[[False, False, False, False, False],
        [False, False, False, False, False],
        [False, False, False, False, False],
        [False, False, False, False, False]],

       [[False, False, False, False, False],
        [ True,  True,  True,  True,  True],
        [ True,  True,  True,  True,  True],
        [ True,  True,  True,  True,  True]],

       [[ True,  True,  True,  True,  True],
        [ True,  True,  True,  True,  True],
        [ True,  True,  True,  True,  True],
        [ True,  True,  True,  True,  True]]], dtype=bool)
>>> (all_FFDI >= 25).sum()
35


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to