Python

  • HOW TO JOIN PYTHON NUMPY ARRAYS?

    The concatenate() method is used to join the numpy arrays by passing sequence of arrays along with the axis and in case if axis is not passed it will consider it as 0. Output- Joining Arrays Using Stack Functions- The stack() method is used for joining two arrays and stacking is same as concatenation, the…

  • HOW TO ITERATE NUMPY ARRAYS?

    We can iterate on the elements of NumPy Arrays by using for loops. Iterating 1-D Array- Output- Iterating 2-D Arrays– Output- Iterating on each element of the 2-D array Output- Iterating 3-D Arrays- Output– To iterate on each scalar value of 3D array, we need to iterate in each dimension- Output- Iterating Arrays Using nditer()…

  • HOW TO RESHAPE ARRAY IN PYTHON NUMPY?

    The method reshape() is used to reshape the python numpy array. Reshaping Python Numpy Array means changing the shape of an array by adding or removing dimensions or changing number of elements in each dimension. Output- Explanation- arr.reshape(4, 2)- Convert the 1-D array- arr with 8 elements into a 2-D array. The outermost dimension will…

  • HOW TO GET THE SHAPE OF AN ARRAY IN PYTHON NUMPY?

    WHAT IS SHAPE OF AN ARRAY IN PYTHON NUMPY? The shape of an array is the number of elements in each dimension. Getting the Shape of an Array- shape attribute of python numpy returns a tuple with each index having the number of corresponding elements. Output- Explanation- The above example returns shape tuple – (2,…

  • WHAT IS THE DIFFERENCE BETWEEN COPY AND VIEW OF AN ARRAY IN PYTHON NUMPY?

    The main difference between a copy and a view of an array is that the copy is a new array and it owns the data, and the view is just a view of the original array and it doesn’t own the data. The copy owns the data where as the view does not own the…

  • HOW TO CREATE VIEW OF PYTHON NUMPY ARRAY?

    View is just a view of the original array, it can be created by view() method and main property of view is that the view does not own the data and any changes made to the view will affect the original array, and any changes made to the original array will affect the view. Output-

  • HOW TO CREATE COPY OF ARRAY IN PYTHON NUMPY?

    Creating copy of an array in Python NumPy- We can create copy of an array in Python NumPy by using copy() method. The copy owns the data and any changes made to the copy will not affect original array, and any changes made to the original array will not affect the copy. Output- Explanation- x…

  • WHAT IS THE DATA TYPE OF ARRAY IN PYTHON NUMPY?

    Python NumPy Data Types Numpy data types and the characters used to represent them are listed below- i – integerb – booleanu – unsigned integerf – floatc – complex floatm – timedeltaM – datetimeO – objectS – stringU – unicode stringV – fixed chunk of memory for other type ( void ) How to check…

  • WHAT IS ARRAY SLICING IN PYTHON NUMPY?

    Accessing elements of an array from one given index to another given index is known as slicing in python. Instead of passing index, we pass slice with step – [start:end:step] If we don’t pass start its considered 0 If we don’t pass end its considered length of array in that dimension If we don’t pass…

  • HOW TO ACCESS ARRAY ELEMENTS IN PYTHON NUMPY?

    Numpy Array Indexing or Accessing Array Elements We can access an array element by referring to its index number. Array indexing is the same as accessing an array element. The indexes in NumPy arrays start with 0. Example- Following example shows that how to access the first element of given array arr. First element of…

  • HOW TO CREATE ARRAY USING NUMPY IN PYTHON?

    The array object in NumPy is called ndarray. We can create a NumPy ndarray object by using the array() function. We can pass a list, tuple or any array-like object into the array() method, and it will be converted into an ndarray. type(): It is a built-in Python function which returns the type of the object passed to…

  • HOW TO INSTALL NumPy ?

    NumPy Installation- If Python and PIP is already installed on a system, then installation of NumPy can be done by using following command In case if the above mentioned command fails, then use a python distribution that already has NumPy installed like, Anaconda, Spyder etc. NumPy Importing- To import NumPy in our application code use…

  • WHAT IS NumPy IN PYTHON?

    NumPy stands for “Numerical Python. NumPy is a open source Python library. NumPy is used for working with arrays. NumPy was created in 2005 by Travis Oliphant. NumPy is written partially in Python, but most of the parts that require fast computation are written in C or C++. NumPy has functions for working in domain…

  • HOW TO HANDLE FILES IN PYTHON?

    We can create, read, update and delete files in python. How to open file in python? File Opening in Python- open() method is used to open the file in the python. It has 2 Parameters – filename and mode. There are four different methods (modes) for opening a file: “r” – Read – Default value.…

  • WHAT IS THE STRING FORMATTING IN PYTHON?

    STRING FORMATTING format() method in python is used to format the selected parts of a string by placing the curly braces {} as placeholder on the selected part of string, which we want to get filled by values provided from user input or database, and running the values through format() method. Example- Add a placeholder/{}…

  • HOW TO GET INPUT FROM USER IN PYTHON?

    User Input in Python using input() method- The following example asks for the username, and when you entered the username, it gets printed on the screen. Python stops executing when it comes to the input() function, and continues when the user has given some input.

  • WHAT IS PYTHON TRY EXCEPT?

    TRY and EXCEPT block is used in the code for the exception handling. Exception Handling Whenever an error or exception occur in our code while executing, the Python will normally stop and generate an error message. These exceptions can be handled using the try statement. The try block is used for testing a block of…

  • WHAT IS PYTHON PIP?

    PIP is a package manager for python packages or modules, it is used to install the additional libraries and packages that are not part of the standard Python library. How to install pip? pip comes pre-installed on the Python versions 3.4 or older. We can check if pip is installed by using the following command…

  • WHAT IS PYTHON RegEx AND HOW TO SEARCH USING PYTHON?

    RegEx in Python RegEx stands for Regular Expression. It is a sequence of characters that form a search pattern. RegEx or search pattern can be used to check if a string contains the specified search pattern. Python has a built in package or module called re which can be imported in python code to work…

  • WHAT IS PYTHON JSON?

    JSON- Stands for Java Script Object Notation, JSON is an open standard text based data interchange format which is easy for machines to parse and generate. JSON in python Python has a built in package called json. json module can be imported in python to work with json data as shown below. To Convert data…