Numpy - Creating Numpy Array

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 5:- Numpy - Creating Numpy Array

NumPy is a fundamental Python library for numerical computing. It provides support for arrays and matrices, along with a wide range of mathematical functions to operate on these arrays. Creating NumPy arrays is a straightforward process. Here are some common methods to create NumPy arrays:

From Python Lists or Tuples:

Using NumPy Functions: NumPy provides several functions to create arrays with specific properties.

Random Number Arrays: NumPy provides functions to generate arrays with random numbers.

These are just a few examples of how to create NumPy arrays. NumPy offers various other functions and methods to manipulate and operate on arrays efficiently, making it a powerful tool for numerical computations in Python.

pythonCopy code

import numpy as np # Creating a 1-dimensional array with random values between 0 and 1 random_array = np.random.rand(5)  # Creates an array of 5 random numbers # Creating a 2-dimensional array with random integers between 0 and 10 random_int_array = np.random.randint(0, 11, (3, 4))  # Creates a 3x4 array of random integers # Creating a 2-dimensional array with random values from a standard normal distribution random_normal_array = np.random.randn(2, 3)  # Creates a 2x3 array of random values

pythonCopy code

import numpy as np # Creating a 1-dimensional array of zeros zeros_array = np.zeros(5)  # Creates [0., 0., 0., 0., 0.] # Creating a 2-dimensional array of ones ones_array = np.ones((3, 4))  # Creates a 3x4 array of ones # Creating a 1-dimensional array with a range of values range_array = np.arange(0, 10, 2)  # Creates [0, 2, 4, 6, 8] # Creating a 1-dimensional array with evenly spaced values linspace_array = np.linspace(0, 1, 5)  # Creates [0., 0.25, 0.5, 0.75, 1.] # Creating a 2-dimensional identity matrix identity_matrix = np.eye(3)  # Creates a 3x3 identity matrix

pythonCopy code

import numpy as np # Creating a 1-dimensional array from a Python list array1d = np.array([1, 2, 3, 4, 5]) # Creating a 2-dimensional array from a Python list of lists array2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # Creating a 1-dimensional array from a Python tuple array_from_tuple = np.array((10, 20, 30, 40))

Disclaimer: 

Copyright Disclaimer under Section 107 of the copyright act 1976, allowance is made for fair use fo purposes such as criticism, comment, news reporting, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favor of fair use.

2. Handling Data

Comments: 0

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?