Question

In: Computer Science

Using Python Shell 2.7, create a file called Assignment6_1.py Create an array based on a basic...

Using Python Shell 2.7, create a file called Assignment6_1.py

Create an array based on a basic array

Create a for loop that will print the array

index the array, print out the index

append an element to the array, print out the array

insert an element into the array, print out the array

pop an element from the array, print out the array

remove an element from the array, print out the array

reverse the order of the array, print the array

NumPy

Using Kali Linux

Take snips of the following:

Create an array using numpy, print the array

Find elements of that array that are larger than a number; Return a boolean value

Create an array of all zeros, print

Create an array of all ones, print

Create a 2x2 identity matrix, print

Create an array filled with random values, print

Solutions

Expert Solution

import numpy as np

#Create an array based on a basic array

basicArray=[34,54,23,45,34,5]

#Create a for loop that will print the array

for i in basicArray:

print i

#index the array, print out the index

for i in range(0,len(basicArray)):

print i

#append an element to the array, print out the array

basicArray.append(45)

print basicArray

#insert an element into the array, print out the array

basicArray.insert(1,22)

print basicArray

#pop an element from the array, print out the array

basicArray.pop()

print basicArray

#remove an element from the array, print out the array

basicArray.remove(34)

print basicArray

#reverse the order of the array, print the array

basicArray.reverse()

print basicArray

########

#NumPy

#Create an array using numpy, print the array

numpyArray=np.array([12,23,43,4,0,2])

print numpyArray

#Find elements of that array that are larger than a number; Return a boolean value

a=numpyArray>10

print a

#Create an array of all zeros, print

z=np.zeros(5)

print z

#Create an array of all ones, print

o=np.ones(5)

print o

#Create a 2x2 identity matrix, print

I=np.eye(2)

print I

#Create an array filled with random values, print

R=np.random.rand(5)

print R


Related Solutions

Python Create a Python script file called hw3.py. Ex. 1. Write a program that inputs numbers...
Python Create a Python script file called hw3.py. Ex. 1. Write a program that inputs numbers from the user until they enter a 0 and computes the product of all these numbers and outputs it. Hint: use the example from the slides where we compute the sum of a list of numbers, but initialize the variable holding the product to 1 instead of 0. print("Enter n") n = int(input()) min = n while n != 0: if n < min:...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called main that does the following: Creates a directory called CyberSecurity-Notes in the current working directory Within the CyberSecurity-Notes directory, creates 24 sub-directories (sub-folders), called Week 1, Week 2, Week 3, and so on until up through Week 24 Within each week directory, create 3 sub-directories, called Day 1, Day 2, and Day 3 Bonus Challenge: Add a conditional statement to abort the script if...
Please make an Array-based implementation of a Binary Tree in Python based on the given file...
Please make an Array-based implementation of a Binary Tree in Python based on the given file below. Make sure to keep the Abstract Data File of the starter code below when building the Array-based implementation. Python Starter Code Given Below: class ArrayBinaryTree(BinaryTree): """Linked representation of a binary tree structure.""" # -------------------------- nested _Node class -------------------------- class _Node: def __init__(self, element, parent=None, left=None, right=None): # -------------------------- nested Position class -------------------------- class Position(BinaryTree.Position): """An abstraction representing the location of a single element."""...
IN PYTHON Complete the following tasks, either in a file or directly in the Python shell....
IN PYTHON Complete the following tasks, either in a file or directly in the Python shell. Using the string class .count() method, display the number of occurrences of the character 's' in the string "mississippi". Replace all occurrences of the substring 'iss' with 'ox' in the string "mississippi". Find the index of the first occurrence of 'p' in the string "mississippi". Determine what the following Python function does and describe it to one of your Lab TAs : def foo(istring):...
Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file...
Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file must satisfy the following. Define a function named rinsert. This function will accept two arguments, the first a list of items to be sorted and the second an integer value in the range 0 to the length of the list, minus 1. This function shall insert the element corresponding to the second parameter into the presumably sorted list from position 0 to one less...
Write a Python program in a file called consonants.py, to solve the following problem using a...
Write a Python program in a file called consonants.py, to solve the following problem using a nested loop. For each input word, replace each consonant in the word with a question mark (?). Your program should print the original word and a count of the number of consonants replaced. Assume that the number of words to be processed is not known, hence a sentinel value (maybe "zzz") should be used. Sample input/output: Please enter a word or zzz to quit:...
USE BASIC PYTHON Focus on Basic file operations, exception handling. Save a copy of the file...
USE BASIC PYTHON Focus on Basic file operations, exception handling. Save a copy of the file module6data.txt (Below) Write a program that will a. Open the file module6data.txt b. Create a second file named processed. txt c. Read the numbers from the first file one at a time. For each number write into second file, if possible, its I. Square ii. Square root iii. Reciprocal (1/number)use a math module function for the square root. use exception handling to trap possible...
Write a python program: There is a file called file 2. File2 is a txt file...
Write a python program: There is a file called file 2. File2 is a txt file and I have written the contents of file 2 below in the exact format it was in notepad. # This comment does not make sense # It is just to make it harder # The job description starts after this comment, notice that it has 4 lines. # This job description has 700150 hay system points\\ the incumbent will administer the spending of kindergarden...
Assignment Requirements Write a python application that consists of two .py files. One file is a...
Assignment Requirements Write a python application that consists of two .py files. One file is a module that contains functions used by the main program. NOTE: Please name your module file: asgn4_module.py The first function that is defined in the module is named is_field_blank and it receives a string and checks to see whether or not it is blank. If so, it returns True, if not it return false. The second function that is defined in the module is named...
"""    CS 125 - Intro to Computer Science    File Name: CS125_Lab1.py    Python Programming...
"""    CS 125 - Intro to Computer Science    File Name: CS125_Lab1.py    Python Programming    Lab 1    Name 1: FirstName1 LastName1    Name 2: FirstName2 LastName2    Description: This file contains the Python source code for deal or no deal. """ class CS125_Lab1(): def __init__(self): # Welcome user to game print("Let's play DEAL OR NO DEAL")    # Define instance variables and init board self.cashPrizes = [.01, .50, 1, 5, 10, 50, 100, 250, 500, 1000, 5000,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT