0

I've got a 3-dim array [rows][cols][3] with values between 0 and X. I need to manipulate a specific dimension in the array. So I've taken a slice of the part I want to manipulate

arr_slice = array[:,:,0]

now I can make some manipulations like arr_slice *= 3 and that will change the original array, as I intended.

However, I need to change values according to a map, which is an array with size X that maps the values of the slice (0-X) to new values. the map is called mapping

so I know mapping[arr_slice] will do what I want, but using it like this: arr_slice = mapping[arr_slice] will of course change only arr_slice and not the original array I have.

So, How can I perform this task to change the original array?

The array is actually an image, that I'm trying to manipulate it's Y values in YIQ format:

im_eq = np.copy(im_orig)

if (rgb):
    im_eq = rgb2yiq(im_eq)
    im = im_eq[:,:,0]
else:
    im = im_eq

mapping = get_cumutative_histogram(im)
im = mapping[im.astype(int)] # the problematic line
1
  • Add a sample case? Commented Nov 22, 2016 at 9:21

1 Answer 1

2

You need to address the slice elements:

im[:] = mapping[im.astype(int)]

for example:

from pylab import *
a = rand(10)
sl = a[4:9]
print sl  # ->: array([ 0.97278179,  0.7894741 ,  0.38051133,  0.42684762, 0.82670638])

sl[:] = 1
print a #-> array([ 0.21125781,  0.4235981 ,  0.81950229,  0.93937973,  1.        ,  1.        ,  1.        ,  1.        ,  1.        ,  0.39047808])
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that's was just what I was looking for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.