Questions: 5 831

Answers by our Experts: 5 728

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

7.Write a code to get the positions where elements of array a and array b are same

a = np.array(['a','b','c','b','c','d','c','d','e','f'])

b = np.array(['g','b','j','b','g','d','i','d','i','h'])


Answer:


Output:

(array([1, 3, 5, 7], dtype=int64),)


8.List the items which are present in array a but NOT present in array b

a = np.array(['a','b','c','d','e'])

b = np.array(['c','d','e','f','g'])


Answer:


array(['a', 'b'], dtype='<U1')


9.Reverse the sequence of rows in 2-D array

a = np.arange(16).reshape(4,4)


Answer:


Output:

array([[12, 13, 14, 15],

    [ 8, 9, 10, 11],

    [ 4, 5, 6, 7],

    [ 0, 1, 2, 3]])


4.Convert a 1-D array into a 2-D array

a = np.array(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'])


Answer:


Output:

array([['a', 'b', 'c'],

    ['d', 'e', 'f'],

    ['g', 'h', 'i'],

    ['j', 'k', 'l']], dtype='<U1')


5.Add 101 to all the values in given array

a = np.arange(16).reshape(4,-1)


Answer:


Output:

array([[101, 102, 103, 104],

    [105, 106, 107, 108],

    [109, 110, 111, 112],

    [113, 114, 115, 116]])


6.Extract the last 5 columns of this 2-D array

a = np.arange(100).reshape(5,-1)


Answer:


Output:

array([[15, 16, 17, 18, 19],

    [35, 36, 37, 38, 39],

    [55, 56, 57, 58, 59],

    [75, 76, 77, 78, 79],

    [95, 96, 97, 98, 99]])


1.Convert the 1-D array to 3-D array

a = np.array([x for x in range(32)])


Answer:


print(o)


Output:

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]]])


2.Convert the value in the array to appropriate data type

a = np.array([[7.2, 5.4, 9.3],

       [3.8, 6.7, 8.5]])


Answer:


print(o)


Output:

[[7 5 9]

 [3 6 8]]


3.Extract value in between 7 to 15 from the given array

a = np.array([2, 6, 1, 9, 10, 3, 27])


Answer:


print(o)


Output:

[ 8 12 9 11]


Develop a python application that will simulate a simple dice game by rolling two dice for the player as his bet followed by another roll of the two dice for the computer.


The mechanics as is follows:

1. If after the roll of the two dice, resulted to same number, then the sum will be doubled.

2. If the value of each dice is different, then just get the sum of the values of each dice.

Who gets the highest value wins the game.


I need the code to have an output stated above.


Develop a python application that will randomly select n integers from 1 to 9 and will count the number of occurrence of the numbers without using the Counter from collections library.



Sample Output 1:

How many numbers?: 5

[4, 6, 8, 3, 3]

1-4

1-6

2-3


I need the code to have an output stated above.


Simple Dice Game


Develop a Python application that will simulate a simple dice game by rolling two dice for the player as his bet followed by another roll of the two dice for the computer.


The mechanics is as follows:


1. If after the roll of the two dice, resulted to same number then the sum will be doubled.


2. If the value of each dice is different, then just get the sum of the values of each dice.


Who gets the highest value wins the game.

Frequency of Numbers


Develop a Python application that will randomly select n integers from 1 to 9 and will count the number of occurrence of the numbers without using the Counter from collections library.


Sample Output:


How many numbers?: 7


[2, 6, 8, 2, 1, 1,6]


2-2


2-6


1-8


2-1

Write a Python code that implements the following: 1. Generate 20 chromosomes, each of which has a length of 5 binary digits (either 0 or 1). 2. Evaluate the fitness of each individual by counting number of ones in each chromosome (as demonstrated in the below table) and compare it to a target chromosomes of all ones (i.e. 11111) Table-1: Fitness of a sample of chromosomes Chromosome Fitness 01110 3 01100 2 00000 0 10111 4 3. Write a function that selects the best fitted individuals for the next population using “Roulette Wheel selection”, by taking the fitness of each individual and generates the probabilities of it. The probability of being selected is proportional to the relative fitness of the individual, that is calculated using the following formula: Hence, the expected output of the individuals in Table-1 is [0.333, 0.222, 0.444] 4.


 A) Create a function called To_Celsius that takes in a temperature in Fahrenheit temperature and returns the equivalent in Celsius.

B) Create another function called To_Fahrenheit that takes in a temperature in Celsius and returns the equivalent in Fahrenheit.

C) Use these functions to write a function called Print_EQ_Temps that prints out the Fahrenheit equivalents of all Celsius temperatures from 0°-100°, and the Celsius equivalents of all Fahrenheit temperatures from 32°-212°. Then, call this function in your program.


Hint: Use for loops to input into your functions.


Write a program that uses loops to print out a design of following using asterisks:

* * * * *

* *

* * * * *

* * * * *

* *

* * * * *


* * * * *

* * * * *


* * * * *

* * * * *


The program should only use the following print statements:

print(“* * * * *”)

print(“* *”)

print(“\n”)

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS