0% found this document useful (0 votes)
4 views9 pages

Python Assignment EJ The Rocks

The document outlines two assignments involving Python programming tasks, including operations on sets, conversions between currencies and data sizes, and checks on numbers. It also describes NumPy arrays, highlighting their features, advantages over other tools like Matlab, and their integration within the Python ecosystem. Additionally, it discusses the reasons for choosing NumPy over alternatives, emphasizing performance, community support, and extensibility.

Uploaded by

prppoojaif21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views9 pages

Python Assignment EJ The Rocks

The document outlines two assignments involving Python programming tasks, including operations on sets, conversions between currencies and data sizes, and checks on numbers. It also describes NumPy arrays, highlighting their features, advantages over other tools like Matlab, and their integration within the Python ecosystem. Additionally, it discusses the reasons for choosing NumPy over alternatives, emphasizing performance, community support, and extensibility.

Uploaded by

prppoojaif21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

ASSINGMENT NO 1

1. Write a program to carry out the following operations on the given set
s={10,2,-3,4,5,88}
a. Number of items in sets s.
b. Maximum elements in sets s.
c. Minimum elements in set s.
d. Sum of all elements in set s.
e. Obtain a new sorted set from s, set s remaining unchanged.
f. Report whether 100 is an elements of set s.
g. Report whether -3 is not an element of set s.

PROGRAM

OUTPUT
2. Write a program to convert U.S. dollars to Indian Rupees.

PROGRAM

OUTPUT

3. Write a program to convert bits to Megabytes, Gigabytes, and Terabytes.

PROGRAM

OUTPUT
4. Write a program to check if a Number is Positive, Negative or Zero.

PROGRAM

OUTPUT

5. Write a python program to reverse a list.


PROGRAM

OUTPUT
ASSINGMENT NO 2
1. Create a tuple and find the minimum and maximum number from it.

PROGRAM

OUTPUT

2. Write a Python program to find the repeated items of a tuple.

PROGRAM

OUTPUT
3. Write a Python function that takes a number as a parameter and check the number
is prime or not.

PROGRAM

OUTPUT

4. Write a Python function that accepts a string and calculate the number of upper
case letters and lower case letters.
PROGRAM

OUTPUT
5. Describe Numpy Array

A NumPy array is a powerful data structure used in the Python programming language,
specifically designed for numerical and scientific computing. It is part of the NumPy library,
which provides support for large, multi-dimensional arrays and matrices, along with a wide
collection of high-level mathematical functions to operate on these arrays.

Here are some key points about NumPy arrays:

1. Homogeneous Data Type:

 Unlike Python lists, which can hold elements of different types (e.g., integers, strings, floats),
a NumPy array holds elements of the same type. This consistency enables NumPy arrays to be
more efficient in terms of memory usage and computational speed.

2. Multi-dimensional:

 A NumPy array can be one-dimensional (like a vector), two-dimensional (like a matrix), or


even higher-dimensional (like a tensor). The number of dimensions is known as the rank of
the array, and the size of each dimension is known as the shape of the array.

3. Efficient Operations:

 NumPy arrays support vectorized operations, meaning you can perform mathematical
operations (like addition, subtraction, multiplication, etc.) on arrays without the need for
explicit loops. These operations are optimized and executed at high speed, making NumPy
arrays ideal for large datasets.

4. Memory Efficiency:

 NumPy arrays are more memory-efficient than Python lists because they store elements in
contiguous blocks of memory, rather than as separate objects.

5. Indexing and Slicing:

 NumPy provides powerful indexing and slicing capabilities. You can access specific
elements, slices, or subarrays using different methods such as integer indexing, boolean
indexing, and fancy indexing.

6. Reshaping:

 NumPy arrays can be reshaped into different shapes without copying the data. This allows for
easy manipulation of array dimensions, which is particularly useful in machine learning and
data science tasks.

7. Broadcasting:

 NumPy supports broadcasting, which allows you to perform operations on arrays of different
shapes. This makes it easy to apply operations element-wise across arrays, even when they
have different shapes.

8. Array Creation:

 NumPy arrays can be created using functions like:


o np.array(): Converts a Python list into a NumPy array.
o np.zeros(), np.ones(): Create arrays filled with zeros or ones, respectively.
o np.arange(): Creates an array with a specified range of values.
o np.linspace(): Creates an array of evenly spaced numbers over a specified range.

9. Mathematical Functions:

 NumPy provides a wide range of mathematical functions such as:


o np.sum(), np.mean(), np.median(): To compute sums, means, and medians.
o np.dot(): For dot products (used in linear algebra).
o np.linalg.inv(): For computing matrix inverses.

6. Why should we use Numpy rather than Matlab, Octave or Yorick?

There are several reasons why one might choose NumPy over other numerical computing tools like
Matlab, Octave, or Yorick. Here's a breakdown of why NumPy is often favored in many scenarios:

1. Integration with Python Ecosystem:

 NumPy is deeply integrated into the broader Python ecosystem. Python offers a vast array of
libraries (e.g., Pandas for data manipulation, Matplotlib for visualization, TensorFlow for
machine learning) that work seamlessly with NumPy arrays. This integration makes NumPy an
excellent choice if you're already using Python for other tasks, as you can leverage the same
language for both general-purpose programming and numerical computing.
2. Open Source and Free:

 NumPy is completely open-source and free to use, just like Octave and Yorick. While Matlab is
proprietary software and requires a paid license, NumPy does not have any such licensing costs,
making it an attractive option for those on a budget or for large-scale projects that require
flexibility without incurring high costs.

3. Performance:

 NumPy is written in C and is highly optimized for performance. Operations on NumPy arrays are
usually faster than those in Matlab and Yorick, especially for large datasets, because NumPy uses
highly efficient array operations (vectorized operations) rather than loops. This can be critical in
data-heavy fields like machine learning or scientific simulations.

4. Popularity and Community Support:

 Python, and by extension, NumPy, is one of the most popular programming languages in the
world. This has led to a massive global community of developers, researchers, and enthusiasts. If
you run into issues or need help, it's much easier to find solutions, tutorials, and community-
driven resources compared to Matlab, Octave, or Yorick.

5. Extensibility and Libraries:

 Python has a rich ecosystem of libraries that complement NumPy, such as:
o Pandas for data manipulation
o SciPy for scientific computing
o Matplotlib/Seaborn for plotting and visualization
o TensorFlow/PyTorch for machine learning
o SymPy for symbolic mathematics This extensive library support makes Python, and NumPy by
extension, a more versatile choice compared to Matlab and Yorick, which are primarily focused
on numerical computing without the broader support.

6. Cross-Platform:

 NumPy runs on multiple platforms like Windows, macOS, and Linux, without any need for
additional tools or configurations. While Matlab and Octave also support multiple platforms,
NumPy's compatibility with Python allows it to work seamlessly across different environments,
making it easier for collaboration, deployment, and scaling.
7. Integration with Other Languages:

 NumPy can be easily integrated with other languages such as C and C++ for performance-critical
sections using tools like Cython or PyPy. It also allows for easy interaction with Java (via
libraries like Jython) and R (via rpy2), among others. Matlab, Octave, and Yorick have more
limited interoperability with other languages.

8. Scalability:

 NumPy works well for both small and large-scale problems, and when paired with tools like
Dask or CuPy (for GPU-based computing), it can scale to extremely large datasets. Matlab can
handle large datasets but may require additional tools (like Matlab's Parallel Computing
Toolbox), and while Octave is open-source, it lacks the same scalability features and libraries as
Python.

9. Ease of Use and Flexibility:

 Python is known for its simple and readable syntax. NumPy inherits this by providing easy-to-
understand code for complex mathematical operations, whereas Matlab, Octave, and Yorick use
their own languages which might require learning a new syntax. For developers already familiar
with Python, NumPy feels natural to integrate into their workflow.

10. Industry Adoption:

 Many tech companies, research institutions, and startups prefer Python due to its flexibility, wide
adoption, and the active Python ecosystem. This has led to the widespread adoption of NumPy in
various fields, including data science, machine learning, scientific computing, and finance. While
Matlab remains popular in academia and certain industries, NumPy’s use in production
environments, particularly in machine learning and AI, is increasing rapidly.

You might also like