Practice Creating NumPy Arrays - Learn NumPy Series

Опубликовано: 15 Сентябрь 2024
на канале: Derrick Sherrill
6k
146

This Video is a part of a NumPy Tutorial Series: Start the entire series here:


In this video we'll get some more practice creating NumPy Arrays. We'll make a 3x3 array, a 4x3 array, look at hetergenously typed array creation, and the practice problem will be to make a 5x2 array in one line.

Download Numpy:
pip3 install numpy

Thanks so much for all the support!! You all are incredible. almost 5k!


Join The Socials -- Picking Shoutouts Across YouTube, Insta, FB, and Twitter!
FB -
Insta -
Twitter -
LinkedIn -
GitHub -
*****************************************************************
Full code from the video:
import numpy as np

# 3x3
seq_a = [1,2,3]
seq_b = [4,5,6]
seq_c = [7,8,9]
array_abc = np.array([seq_a, seq_b, seq_c])
# Creating an Array from multiple lists. Note how we have to include all the lists in a second set of square brackets
# This is one way to make a nested list in Python
print(array_abc)

# What happens when we add floats as a new row in our array?
seq_d = [10.5,11.5,12.5]


array_abcd = np.array([seq_a, seq_b, seq_c, seq_d])
print(array_abcd)
# When we add floats to our numpy array, the entire dataset must then have the same data type.
# int data type does not accurately explain our float numbers, so the entire dataset is converted to float

# Challenge Answer: Make a 2x5 Array in one line with nested lists
array_d = np.array([[1,2],[3,4],[5,6],[7,8],[9,10]])



Packages (& Versions) used in this video:
Python 3.7
NumPy 1.17

*****************************************************************
Code from this tutorial and all my others can be found on my GitHub:


Check out my website:


If you liked the video - please hit the like button. It means more than you know. Thanks for watching and thank you for all your support!!

Always looking for suggestions on what video to make next -- leave me a comment with your project! Happy Coding!