Question

4 What are the outputs of the following codes? import numpyas np A = np.arange(11)**2 B = A[2:5] C = A[ :-1] D = A[] D[: 5:2]
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Given Code:

import numpy as np

A = np.arange(11)**2

B = A[2:5]

C = A[::-1]

D = A[:]

D[:5:2] = 200

for i in A:

print(i)

print(np.sqrt(i))

Code Image:

Output Image:

Explanation:

A = np.arange(11)**2 => A = [ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

B = A[2:5] => B = [4, 9, 16]

C = A[::-1] => C = [100, 81, 64, 49, 36, 25, 16, 9, 4, 1, 0]

D = A[:] => D = [ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

D[:5:2] = 200 => D = [ 200, 1, 200, 9, 200, 25, 36, 49, 64, 81, 100], it will also change the A as it is pointing to same data and rest is what is printed in the output.

Please do upvote!

Thanks :)

Add a comment
Know the answer?
Add Answer to:
4 What are the outputs of the following codes? import numpyas np A = np.arange(11)**2 B...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python 1 import matplotlib.pyplot as plt 2 import numpy as np 3 4 abscissa = np.arange(20) 5 plt....

    python 1 import matplotlib.pyplot as plt 2 import numpy as np 3 4 abscissa = np.arange(20) 5 plt.gca().set_prop_cycle( ’ color ’ , [ ’ red ’ , ’ green ’ , ’ blue ’ , ’ black ’ ]) 6 7 class MyLine: 8 9 def __init__(self, * args, ** options): 10 #TO DO: IMPLEMENT FUNCTION 11 pass 12 13 def draw(self): 14 plt.plot(abscissa,self.line(abscissa)) 15 16 def get_line(self): 17 return "y = {0:.2f}x + {1:.2f}".format(self.slope, self.intercept) 18 19 def __str__(self):...

  • Python...I don't know what is wrong with my code: import numpy as np from mpi4py import...

    Python...I don't know what is wrong with my code: import numpy as np from mpi4py import MPI array= [14,175, 15,055, 16,616, 17,495, 18,072, 19,390] array1,array2= array[ : :2], array[1: :2] print (array1) print (array2) /////it should print array1 = [1,4175, 16,616,18,072] array2= [15,055, 17,495, 19,390]

  • ompute the following binomial probabilities using the table of Cumulative Binomial Probabilities. Give your answer to...

    ompute the following binomial probabilities using the table of Cumulative Binomial Probabilities. Give your answer to 3 places past the decimal. Compute the following binomial probabilities using the table of Cumulative Binomial Probabilities. Give your answer to 3 places past the decimal a) Binomial cdf value: B(9; 25, 0.4) 0.425 正确答案! 您的证明编号是159-5108 (O LAHIR 以煎的尝试 b.) Binomial cdf value: B(6; 20, 0.2) 0.913 正确答案! 您的证明编号是159-7057。)以前的尝试 c) Binomial pmf value: b(8; 20, 0.4) 0.180 正确答案! 您的证明编号是159-8630 ⓞEAELAR d) Binomial pmf value:...

  • Accidents recur in a factory at the rate of 5 per week. Assume that accidents happen...

    Accidents recur in a factory at the rate of 5 per week. Assume that accidents happen randomly and independently of each other. Answer the following questions to 3 places past the decimal. a) What is the probability that there is at most 1 accident in a week? 0.0400 正确答案! 您的证明编号是160-831 的尝试 b) What is the probability that there are 2 accidents in a week? 0.0840 正确答案! 您的证明编号是160-3065 c) What is the probability of no accidents on a given day? Assume...

  • (5 points) Analyze the following codes. b) import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import...

    (5 points) Analyze the following codes. b) import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { Button btOK = new Button("OK"); Button btCancel = new Button("Cancel"); EventHandler<ActionEvent> handler = new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("The OK button is clicked"); } }; btOK.setOnAction(handler); btCancel.setOnAction(handler); HBox pane = new HBox(5); pane.getChildren().addAll(btOK, btCancel); Scene...

  • 5. (6 pts) What is the outputs of following section of a program? int a[10] =...

    5. (6 pts) What is the outputs of following section of a program? int a[10] = {1,2,3,2, 5, 6, 7, 8 , 9, y): int i - 0, 30: while (i<10) coutくく3くくendl ; 6. (6 pts) What is output of following set of instructions in a C++ program: (In this problem both x and y represent positive integers) int a[10]={-1, 3=0; 2, 7, -4, 11, -2, 3, -9); x, -y, int for (int i-0:i<10:i++) if (a [1]<0) s+ai] coutくく3(くend-; 7....

  • This is my code: import numpy as np import pandas as pd import sys from keras.models...

    This is my code: import numpy as np import pandas as pd import sys from keras.models import Sequential from keras.layers import Dense from sklearn.preprocessing import StandardScaler from keras.layers.normalization import BatchNormalization from keras.layers import Dropout file_full=pd.read_csv("/Users/anwer/Desktop/copy/FULL.csv") file_bottom=pd.read_csv("/Users/anwer/Desktop/copy/bottom.csv") train=[] train_targets=[] test=[] test_targets=[] p=[] q=[]    # We will generate train data using 50% of full data and 50% of bottom data. #is train target for labeling ? yes for train data train_df = file_full[:len(file_full)//2] labels=[ 0 for i in range(len(file_full)//2)] train_df=train_df.append(file_bottom[:len(file_bottom)//2]) for...

  • You may import the following library functions in your module: from fractions import gcd from math...

    You may import the following library functions in your module: from fractions import gcd from math import log from math import floor You may also use: • the .bit_length() method to efficiently obtain the bit length of an integer, • the abs() function for computing the absolute value of an integer, • and the // operator for integer division (you should avoid using / because it does not work for very large integers). Implement the following Python functions. These functions...

  • You may import the following library functions in your module: from fractions import gcd from math...

    You may import the following library functions in your module: from fractions import gcd from math import floor from random import randint You may also use: • the built-in pow() function to compute modular exponents efficiently (i.e., ak mod n can be written in Python as pow(a,k,n)), • the sum() function returns the sum of a list of integers (sum(1,2,3,4) returns 10). problem 1 a. Implement a function invPrime(a, p) that takes two integers a and p > 1 where...

  • Given the following pseudo-code, please show what the outputs will be at LINE A, B, C...

    Given the following pseudo-code, please show what the outputs will be at LINE A, B, C and D. please put down “inconclusive” if you think the CPU process scheduling could potentially result in multiple values for integer i. You will receive partial credit if you draw the process tree. int i = 0; int main(){                         if (fork() == 0) {                         i++;                         if (fork() == 0){                                     if (fork() == 0){                                                 i++;                                                 print value...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT