4 Write a Code to Sort an Array in Numpy by the (N-1)Th Column.
This can be achieved by using argsort() function. Let us take an array X; the code to sort the (n-1)th column will be x[x [: n-2].argsoft()]
The code is as shown below:
>>X[X[:,1].argsort()]
Output:array([[1,2,3],[0,5,2],[2,3,4]])
8 Explain join() and split() functions in Python.
The join() function can be used to combine a list of strings based on a delimiter into a single string.
The split() function can be used to split a string into a list of strings based on a delimiter.
string = “This is a string.”
string_list = string.split( ) #delimiter is âspaceâ character or â â
print(string_list) #output: [This, is, a, string.]
print( .join(string_list)) #output: This is a string.
3 How Do You Get Indices of N Maximum Values in a Numpy Array?
>>print(arr.argsort( ) [ -N: ][: : -1])
10 How multithreading is achieved in Python?
5 Write a program to count the number of capital letters in a file?
Output:
Q8 Explain how you can set up the Database in Django.
Ans: You can use the command edit mysite/setting.py, it is a normal python module with module level representing Django settings.
Django uses SQLite by default; it is easy for Django users as such it won’t require any other type of installation. In the case your database choice is different that you have to the following keys in the DATABASE ‘default’ item to match your database connection settings.
Django uses SQLite as a default database, it stores data as a single file in the filesystem. If you do have a database server—PostgreSQL, MySQL, Oracle, MSSQL—and want to use it rather than SQLite, then use your database’s administration tools to create a new database for your Django project. Either way, with your (empty) database in place, all that remains is to tell Django how to use it. This is where your project’s settings.py file comes in.
We will add the following lines of code to the setting.py file:
Q3 What are the generators in python?
Ans: Functions that return an iterable set of items are called generators.