Message Boards Message Boards

0
|
2061 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:

[?] Select and replace on a 2D lists of data?

Posted 7 years ago

How do I select range of elements on a 2D lists of data and replace the selected elements with a specified range of values. For example if

K = {{4, 6, 7, -8, 2, 1, 9, 6, 10, 1}, {2, 2, 3, 9, -10, 3, 4, 7, 8, 1}, {5, 4, 2, 1, 10, 8, 7, 3, -9, 5}}

I like to select elements in the range of (5 to 10) and range of (-5 to -10), replace all the selected with range of (1 to 3) and (-1 to -3) respectively.

POSTED BY: PAUL EDIGBUE
4 Replies

Strange how it duplicated your post under my name...

What I posted was that you can certainly use Map[] to map a replacement function over your list with "rules" in it. or if your replacement is as simple as you indicate, you can just do:

K /. {5-> 2, -5 -> -2}

Regards

POSTED BY: Neil Singer

How do I select and replace on a 2D lists of data?.

POSTED BY: Neil Singer

You need to give some examples. I don't understand what you are asking. For example, How do you know what to replace a value with if you are replacing 5 values in the range of 5 to 10 with 3 values in the range of 1 to 3?

POSTED BY: Neil Singer
Posted 7 years ago

I want to replace values higher than a specific number e.g 5 and -5, with specific values e.g replace 5 with 2 and -5 with -2.

POSTED BY: PAUL EDIGBUE
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract