Found 34489 Articles for Programming

Plotting solar image in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

255 Views

In Python provides SunPy package for create solar image. In this package has different files which are solar data of proton/electron fluxes from various solar observatory and solar labs. Using pip install sunpy command, we can install sunpy package. Here we plot a sample AIA image. AIA is Atmospheric Imaging Assembly. This is another instrument board of the SDO. Here we use sunpy.Map() function to create a map from one of the supported data products. Example code import sunpy.map import matplotlib.pyplot as plt import sunpy.data.sample my_aia = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE) fig = plt.figure() ax = plt.subplot(111, projection=my_aia) my_aia.plot() my_aia.draw_limb() ... Read More

Scraping and Finding Ordered Word in a Dictionary in Python

karthikeya Boyini
Updated on 26-Jun-2020 12:37:10

525 Views

For solving this problem we need requests module.For installing requests module, we need this command to get executed at command line.pip install requestsScrapingImport requests module.Then we need to fetch data from URL.Using UTF-8 decode the text.Then convert string into a list of words.Ordered FindingTraverse the list of words using loop.Then compare the ASCII value of adjacent character of each word.If the comparison is true then print ordered word otherwise store the unordered word.Example codeimport requests    def Words_find():       my_url = ""#put thisurl of .txt files in any website       my_fetchData = requests.get(my_url)       ... Read More

Ways to sort list of dictionaries by values in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

144 Views

Here one dictionary is given, our task is to sort by their values. Two values are present in this dictionary one is name and another is roll. First we display sorted list by their roll using lambda function and in-built sorted function. Second we display sorted list by the name and roll and third by their name. Example code Live Demo # Initializing list of dictionaries my_list1 = [{ "name" : "Adwaita", "roll" : 100}, { "name" : "Aadrika", "roll" : 234 }, { "name" : "Sakya" , "roll" : 23 }] print ("The list is sorted ... Read More

Matrix manipulation in Python

AmitDiwan
Updated on 11-Aug-2022 11:24:53

14K+ Views

We can easily perform matrix manipulation in Python using the Numpy library. NumPy is a Python package. It stands for 'Numerical Python'. It is a library consisting of multidimensional array objects and a collection of routines for processing of array. Using NumPy, mathematical and logical operations on arrays can be performed. Install and Import Numpy To install Numpy, use pip − pip install numpy Import Numpy − import numpy Add, Subtract, Divide and Multiply matrices We will use the following Numpy methods for matrix manipulations − numpy.add() − Add two matrices numpy.subtract() − Subtract two matrices numpy.divide() ... Read More

Underscore(_) in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

535 Views

In Python in some cases we use Single Underscore(_) and some cases we use Double Underscores (__). In Python has following cases, where we use underscore. If we want to store the value of last expression in interpreter. If we want to ignore some values. For declaration of variable or function. To separate digits of number lateral value. It is also used as ‘Internationalization (i18n)’ or ‘Localization (l10n)’ functions. Now some examples on every cases. Used in interpreter The Python Interpreter stores the last expression value in the '_'. >>> 20 20 >>> _ ... Read More

Different Methods to find Prime Number in Python

Samual Sam
Updated on 26-Jun-2020 12:31:53

1K+ Views

First we need to know what a prime number is.A prime number always a positive integer number and divisible by exactly 2 integers (1 and the number itself), 1 is not a prime number.Now we shall discuss some methods to find Prime Number.Method1Using For loopsExampledef primemethod1(number):    # Initialize a list    my_primes = []    for pr in range(2, number):       isPrime = True    for i in range(2, pr):    if pr % i == 0:       isPrime = False    if isPrime:       my_primes.append(pr)    print(my_primes) primemethod1(50)Output[2, 3, 5, 7, 11, ... Read More

Page Rank Algorithm and Implementation using Python

karthikeya Boyini
Updated on 26-Jun-2020 12:32:55

4K+ Views

The PageRank algorithm is applicable in web pages. Web page is a directed graph, we know that the two components of Directed graphsare -nodes and connections. The pages are nodes and hyperlinks are the connections, the connection between two nodes.We can find out the importance of each page by the PageRank and it is accurate. The value of the PageRank is the probability will be between 0 and 1.The PageRank value of individual node in a graph depends on the PageRank value of all the nodes which connect to it and those nodes are cyclically connected to the nodes whose ... Read More

Binary to decimal and vice-versa in Python

AmitDiwan
Updated on 11-Aug-2022 11:22:14

749 Views

In this article, we will see how to convert Binary to Decimal and Decimal to Binary. Binary is the simplest kind of number system that uses only two digits of 0 and 1 (i.e. value of base 2). Since digital electronics have only these two states (either 0 or 1), so binary number is most preferred in modern computer engineer, networking and communication specialists, and other professionals. Decimal number system has base 10 as it uses 10 digits from 0 to 9. In decimal number system, the successive positions to the left of the decimal point represent units, tens, hundreds, ... Read More

Quine in Python

AmitDiwan
Updated on 12-Aug-2022 12:17:14

1K+ Views

The Quine is a program, which takes no input, but it produces output. It will show its own source code. Additionally, Quine has some conditions. We cannot open the source code file inside the program. Example 1 Here a simple string formatting is working. We are defining a variable ‘a’, and inside a, we are storing ‘a=%r;print (a%%a)’ Then we are printing the value of a, and also replacing %r with the value of a. Thus the quine is working − a='a=%r;print (a%%a)';print (a%a) Output a='a=%r;print (a%%a)';print (a%a) Example 2 We defined a variable _ and assigned ‘_=%r;print ... Read More

Handling missing keys in Python dictionaries

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

1K+ Views

In Python there is one container called the Dictionary. In the dictionaries, we can map keys to its value. Using dictionary the values can be accessed in constant time. But when the given keys are not present, it may occur some errors. In this section we will see how to handle these kind of errors. If we are trying to access missing keys, it may return errors like this. Example code Live Demo country_dict = {'India' : 'IN', 'Australia' : 'AU', 'Brazil' : 'BR'} print(country_dict['Australia']) print(country_dict['Canada']) # This will return error Output AU --------------------------------------------------------------------------- KeyErrorTraceback (most ... Read More

Advertisements