Skip to main content
Tweeted twitter.com/StackMma/status/1434350741448187905
Became Hot Network Question
improve formatting
Source Link
creidhne
  • 5.8k
  • 6
  • 25
  • 32

How to havefind a median of odd and even numbers from a list of numbers

For a given list, say {94,35,47,29,86,40,46,72,87}, how can I havefind a list of even and odd numbers.

GroupBy[{94,35,47,29,86,40,46,72,87,84,49,82,100,99,7,70,67,63,13,
  91,18,94,94,15,72,39,4,7,31,67,65,37,93,9,4,84,97,60,48,61,91,24,10,
  46,42,28,41,36,62,70,78,38,80,70,63,20,21,7,54,26,17,73,100,56,36,
  54,100,46,0,59,77,80,57,82,63,74,8,47,68,74,54,57,4,90,14,31,88,23,
  30,37,95,44,100,12,23,48,4,14,100,57},EvenQ] 
True->  {94,86,40,46,72,84,82,100,70,18,94,94,72,4,4,84,60,48,24,10,46,
  42,28,36,62,70,78,38,80,70,20,54,26,100,56,36,54,100,46,0,80,
  82,74,8,68,74,54,4,90,14,88,30,44,100,12,48,4,14,100}, 
False->  {35,47,29,87,49,99,7,67,63,13,91,15,39,7,31,67,65,37,93,9,97,
  61,91,41,63,21,7,17,73,59,77,57,63,47,57,31,23,37,95,23,57}\

What is needed is the count.True True->54,False False->49.

With CountsBy as suggested by @sjoerd-smit, I get the count of even and odd numbers in one command. CountsBy[{94,35,47,29,86,40,46,72,87,84,49,82,100,99,7,70,67,63,13,91,18,94,94,15,72,39,4,7,31,67,65,37,93,9,4,84,97,60,48,61,91,24,10,46,42,28,41,36,62,70,78,38,80,70,63,20,21,7,54,26,17,73,100,56,36,54,100,46,0,59,77,80,57,82,63,74,8,47,68,74,54,57,4,90,14,31,88,23,30,37,95,44,100,12,23,48,4,14,100,57},EvenQ]

CountsBy[{94,35,47,29,86,40,46,72,87,84,49,82,100,99,7,70,67,63,13,
  91,18,94,94,15,72,39,4,7,31,67,65,37,93,9,4,84,97,60,48,61,91,24,10,
  46,42,28,41,36,62,70,78,38,80,70,63,20,21,7,54,26,17,73,100,56,36,
  54,100,46,0,59,77,80,57,82,63,74,8,47,68,74,54,57,4,90,14,31,88,23,
  30,37,95,44,100,12,23,48,4,14,100,57},EvenQ]

Input: Median[{35,47,29,87,49,99,7,67,63,13,91,15,39,7,31,67,65,37,93,9,97,61,91,41,63,21,7,17,73,59,77,57,63,47,57,31,23,37,95,23,57}]

Median[{35,47,29,87,49,99,7,67,63,13,91,15,39,7,31,67,65,37,93,
9,97,61,91,41,63,21,7,17,73,59,77,57,63,47,57,31,23,37,95,23,57}] 

How to have a median of odd and even numbers from a list of numbers

For a given list, say {94,35,47,29,86,40,46,72,87}, how can I have a list of even and odd numbers.

GroupBy[{94,35,47,29,86,40,46,72,87,84,49,82,100,99,7,70,67,63,13,91,18,94,94,15,72,39,4,7,31,67,65,37,93,9,4,84,97,60,48,61,91,24,10,46,42,28,41,36,62,70,78,38,80,70,63,20,21,7,54,26,17,73,100,56,36,54,100,46,0,59,77,80,57,82,63,74,8,47,68,74,54,57,4,90,14,31,88,23,30,37,95,44,100,12,23,48,4,14,100,57},EvenQ] 
True->{94,86,40,46,72,84,82,100,70,18,94,94,72,4,4,84,60,48,24,10,46,42,28,36,62,70,78,38,80,70,20,54,26,100,56,36,54,100,46,0,80,82,74,8,68,74,54,4,90,14,88,30,44,100,12,48,4,14,100},False->{35,47,29,87,49,99,7,67,63,13,91,15,39,7,31,67,65,37,93,9,97,61,91,41,63,21,7,17,73,59,77,57,63,47,57,31,23,37,95,23,57}\

What is needed is the count.True->54,False->49.

With CountsBy as suggested by @sjoerd-smit, I get the count of even and odd numbers in one command. CountsBy[{94,35,47,29,86,40,46,72,87,84,49,82,100,99,7,70,67,63,13,91,18,94,94,15,72,39,4,7,31,67,65,37,93,9,4,84,97,60,48,61,91,24,10,46,42,28,41,36,62,70,78,38,80,70,63,20,21,7,54,26,17,73,100,56,36,54,100,46,0,59,77,80,57,82,63,74,8,47,68,74,54,57,4,90,14,31,88,23,30,37,95,44,100,12,23,48,4,14,100,57},EvenQ]

Input: Median[{35,47,29,87,49,99,7,67,63,13,91,15,39,7,31,67,65,37,93,9,97,61,91,41,63,21,7,17,73,59,77,57,63,47,57,31,23,37,95,23,57}]

How to find a median of odd and even numbers from a list of numbers

For a given list, say {94,35,47,29,86,40,46,72,87}, how can I find a list of even and odd numbers.

GroupBy[{94,35,47,29,86,40,46,72,87,84,49,82,100,99,7,70,67,63,13,
  91,18,94,94,15,72,39,4,7,31,67,65,37,93,9,4,84,97,60,48,61,91,24,10,
  46,42,28,41,36,62,70,78,38,80,70,63,20,21,7,54,26,17,73,100,56,36,
  54,100,46,0,59,77,80,57,82,63,74,8,47,68,74,54,57,4,90,14,31,88,23,
  30,37,95,44,100,12,23,48,4,14,100,57},EvenQ] 
True->  {94,86,40,46,72,84,82,100,70,18,94,94,72,4,4,84,60,48,24,10,46,
  42,28,36,62,70,78,38,80,70,20,54,26,100,56,36,54,100,46,0,80,
  82,74,8,68,74,54,4,90,14,88,30,44,100,12,48,4,14,100}, 
False->  {35,47,29,87,49,99,7,67,63,13,91,15,39,7,31,67,65,37,93,9,97,
  61,91,41,63,21,7,17,73,59,77,57,63,47,57,31,23,37,95,23,57}

What is needed is the count. True->54, False->49.

With CountsBy as suggested by @sjoerd-smit, I get the count of even and odd numbers in one command.

CountsBy[{94,35,47,29,86,40,46,72,87,84,49,82,100,99,7,70,67,63,13,
  91,18,94,94,15,72,39,4,7,31,67,65,37,93,9,4,84,97,60,48,61,91,24,10,
  46,42,28,41,36,62,70,78,38,80,70,63,20,21,7,54,26,17,73,100,56,36,
  54,100,46,0,59,77,80,57,82,63,74,8,47,68,74,54,57,4,90,14,31,88,23,
  30,37,95,44,100,12,23,48,4,14,100,57},EvenQ]

Input:

Median[{35,47,29,87,49,99,7,67,63,13,91,15,39,7,31,67,65,37,93,
9,97,61,91,41,63,21,7,17,73,59,77,57,63,47,57,31,23,37,95,23,57}] 
added 766 characters in body
Source Link

How to have a listmedian of odd and even numbers from a list of numbers

With CountsBy as suggested by @sjoerd-smit, I get the count of even and odd numbers in one command. CountsBy[{94,35,47,29,86,40,46,72,87,84,49,82,100,99,7,70,67,63,13,91,18,94,94,15,72,39,4,7,31,67,65,37,93,9,4,84,97,60,48,61,91,24,10,46,42,28,41,36,62,70,78,38,80,70,63,20,21,7,54,26,17,73,100,56,36,54,100,46,0,59,77,80,57,82,63,74,8,47,68,74,54,57,4,90,14,31,88,23,30,37,95,44,100,12,23,48,4,14,100,57},EvenQ]

By Median applied individually, I could get the medians of even and odd numbers in the list.

Input: Median[{35,47,29,87,49,99,7,67,63,13,91,15,39,7,31,67,65,37,93,9,97,61,91,41,63,21,7,17,73,59,77,57,63,47,57,31,23,37,95,23,57}]

Output: 49

Similarly, for the list of even numbers.

Might be a way to get the same with one command.

How to have a list of odd and even numbers from a list of numbers

How to have a median of odd and even numbers from a list of numbers

With CountsBy as suggested by @sjoerd-smit, I get the count of even and odd numbers in one command. CountsBy[{94,35,47,29,86,40,46,72,87,84,49,82,100,99,7,70,67,63,13,91,18,94,94,15,72,39,4,7,31,67,65,37,93,9,4,84,97,60,48,61,91,24,10,46,42,28,41,36,62,70,78,38,80,70,63,20,21,7,54,26,17,73,100,56,36,54,100,46,0,59,77,80,57,82,63,74,8,47,68,74,54,57,4,90,14,31,88,23,30,37,95,44,100,12,23,48,4,14,100,57},EvenQ]

By Median applied individually, I could get the medians of even and odd numbers in the list.

Input: Median[{35,47,29,87,49,99,7,67,63,13,91,15,39,7,31,67,65,37,93,9,97,61,91,41,63,21,7,17,73,59,77,57,63,47,57,31,23,37,95,23,57}]

Output: 49

Similarly, for the list of even numbers.

Might be a way to get the same with one command.

added 978 characters in body
Source Link

For a given list, say {94,35,47,29,86,40,46,72,87}, how can I have a list of even and odd numbers.

Here is the output after trying with the suggested solution in the answer.

enter image description here

After putting the number in list as told by @Nasser, I got the intended output.

I am seeking to solve this problem:

Create an Association that lists the Median of the even and odd numbers respectively under the keys True and False. (Hint: Use GroupBy with EvenQ.)

By applying GroupBy, I could now list the even and odd numbers:

Input:

GroupBy[{94,35,47,29,86,40,46,72,87,84,49,82,100,99,7,70,67,63,13,91,18,94,94,15,72,39,4,7,31,67,65,37,93,9,4,84,97,60,48,61,91,24,10,46,42,28,41,36,62,70,78,38,80,70,63,20,21,7,54,26,17,73,100,56,36,54,100,46,0,59,77,80,57,82,63,74,8,47,68,74,54,57,4,90,14,31,88,23,30,37,95,44,100,12,23,48,4,14,100,57},EvenQ] 

Output:

True->{94,86,40,46,72,84,82,100,70,18,94,94,72,4,4,84,60,48,24,10,46,42,28,36,62,70,78,38,80,70,20,54,26,100,56,36,54,100,46,0,80,82,74,8,68,74,54,4,90,14,88,30,44,100,12,48,4,14,100},False->{35,47,29,87,49,99,7,67,63,13,91,15,39,7,31,67,65,37,93,9,97,61,91,41,63,21,7,17,73,59,77,57,63,47,57,31,23,37,95,23,57}\

What is needed is the count.True->54,False->49.

For a given list, say {94,35,47,29,86,40,46,72,87}, how can I have a list of even and odd numbers.

Here is the output after trying with the suggested solution in the answer.

enter image description here

After putting the number in list as told by @Nasser, I got the intended output.

For a given list, say {94,35,47,29,86,40,46,72,87}, how can I have a list of even and odd numbers.

Here is the output after trying with the suggested solution in the answer.

enter image description here

After putting the number in list as told by @Nasser, I got the intended output.

I am seeking to solve this problem:

Create an Association that lists the Median of the even and odd numbers respectively under the keys True and False. (Hint: Use GroupBy with EvenQ.)

By applying GroupBy, I could now list the even and odd numbers:

Input:

GroupBy[{94,35,47,29,86,40,46,72,87,84,49,82,100,99,7,70,67,63,13,91,18,94,94,15,72,39,4,7,31,67,65,37,93,9,4,84,97,60,48,61,91,24,10,46,42,28,41,36,62,70,78,38,80,70,63,20,21,7,54,26,17,73,100,56,36,54,100,46,0,59,77,80,57,82,63,74,8,47,68,74,54,57,4,90,14,31,88,23,30,37,95,44,100,12,23,48,4,14,100,57},EvenQ] 

Output:

True->{94,86,40,46,72,84,82,100,70,18,94,94,72,4,4,84,60,48,24,10,46,42,28,36,62,70,78,38,80,70,20,54,26,100,56,36,54,100,46,0,80,82,74,8,68,74,54,4,90,14,88,30,44,100,12,48,4,14,100},False->{35,47,29,87,49,99,7,67,63,13,91,15,39,7,31,67,65,37,93,9,97,61,91,41,63,21,7,17,73,59,77,57,63,47,57,31,23,37,95,23,57}\

What is needed is the count.True->54,False->49.

added 83 characters in body
Source Link
Loading
added 169 characters in body
Source Link
Loading
Source Link
Loading