Question

In: Computer Science

LEVEL ONE Lists and indexing Create a list x that spans 1 to 100 using 5...

LEVEL ONE

  1. Lists and indexing
    1. Create a list x that spans 1 to 100 using 5 unit increments.

                                Hint: Use the inline for and range().

  1. Create a list y containing the elements from x that are divisible by 2.

                                Hint: Explore the for … if … statement.

  1. Do b. in another manner. Hint: Use , e.g., array() and where() from numpy.

LEVEL TWO

  1. Arrays in numpy
    1. Create an array x that contains a random set of 100 uniform(0,10) variables.
  2.                                 Hint: Explore numpy.random.rand().

    1. Find the values in x greater than 5.
    2. Find the maximum and minimum values without sorting. Hint: Explore numpy.min() and numpy.max().
    1. Find the indices associated with the min/max in c.   Hint: Explore numpy.argmin() and numpy.argmax().

NB: THIS IS A PYTHON ASSIGNMENT   

Solutions

Expert Solution

Level One

x = [ele for ele in range(1,100,5)] # list x from 1 to 100 with interval of 5
print(x) #print list x

y = [num for num in x if num % 2 == 0] # list y which has elements from x divisble by 2
print(y) #print list y

Using Numpy

import numpy as np #import numpy package
x = np.arange(1,100,5) # array x from 1 to 100 with interval of 5
print(x) #print array x

y = x[np.where(x%2==0)] # array y which has elements from x divisble by 2
print(y) #print array y

Level Two

x = np.random.uniform(0,10,100) # array of 100 elements in uniform distribution with low = 0 and high = 10

print(x[x>5]) # values from x which are greater than 5
print("*"*100)
print(min(x), max(x)) #minimum and maximum value of array x
print("*"*100)
print(np.argmin(x), np.argmax(x)) # index of minimum and maximum value of x

Screenshot

Level one without using Numpy

Level one using Numpy

Level Two

Comments has been given in the code. Also, Screenshot of code as well as output has been given for the reference.


Related Solutions

The variable x takes the values ​​from 1 to 100, with these values, create two lists,...
The variable x takes the values ​​from 1 to 100, with these values, create two lists, one where the prime numbers are stored in one, and another where the non-prime numbers are stored, indicate and print the result
Two sorted lists have been created, one implemented using a linked list (LinkedListLibrary linkedListLibrary) and the...
Two sorted lists have been created, one implemented using a linked list (LinkedListLibrary linkedListLibrary) and the other implemented using the built-in Vector class (VectorLibrary vectorLibrary). Each list contains 100 books (title, ISBN number, author), sorted in ascending order by ISBN number. Complete main() by inserting a new book into each list using the respective LinkedListLibrary and VectorLibrary InsertSorted() methods and outputting the number of operations the computer must perform to insert the new book. Each InsertSorted() returns the number of...
Creating a list/tuple in python 2. Using a list of lists containing X’s and O’s to...
Creating a list/tuple in python 2. Using a list of lists containing X’s and O’s to represent a tic tac toe board, write code to check if the board has a winner.
Using Python : Create a 4×5 4 × 5 array ? X with random value. Print...
Using Python : Create a 4×5 4 × 5 array ? X with random value. Print out ? X , as well as the largest value of each column.
Using C++, you will create a program, where you will create two doubly linked lists. These...
Using C++, you will create a program, where you will create two doubly linked lists. These doubly linked lists will contain integers within them. Using the numbers in both of these linked lists, you add the numbers together, and insert the addition of the two numbers into a singly linked list. the input can be from the user or you just write the input. for example, if one number in the doubly linked list is 817 and in the other...
Create a flowchart using the bisection method when a=2 and b=5 and y=(x-3)3-1
Create a flowchart using the bisection method when a=2 and b=5 and y=(x-3)3-1
How to do this in Python (using Lists): Create a python program that allows a user...
How to do this in Python (using Lists): Create a python program that allows a user to display, sort and update as needed a List of U.S States containing the State Capital and State Bird. You will need to embed the State data into your Python code. The user interface will allow the user to perform the following functions: 1. Display all U.S. States in Alphabetical order along with Capital and Bird 2. Search for a specific state and display...
Create an unsorted LIST class. Each list should be able to store 100 names.
Create an unsorted LIST class. Each list should be able to store 100 names.
A solid steel bar with dimensions of 1 x 4 inches spans a 20 foot gap....
A solid steel bar with dimensions of 1 x 4 inches spans a 20 foot gap. The beam is loaded with a single 1000 lb load a t mid span. Calculate the deflection of the beam at every foot along it s length . (That is, calculate the deflecton at x=0, 12,24, 36 ... inches) INCLUDE the weight of the beam. Plot the deflection, y, versus x
Using the Chinese remainder theorem solve for x: x = 1 mod 3 x = 5...
Using the Chinese remainder theorem solve for x: x = 1 mod 3 x = 5 mod 7 x = 5 mod 20 Please show the details, I`m trying to understand how to solve this problem since similar questions will be on my exam.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT