NumPy Creating Arrays
📌 NumPy — Creating Arrays
NumPy provides multiple ways to create arrays depending on your needs. The most common method is using the np.array() function, but NumPy also includes built-in methods for creating:
✔ zeros
✔ ones
✔ sequences
✔ random values
✔ identity matrices
✔ custom ranges
🧩 1. Creating Array Using np.array()
Output:
Multi-Dimensional Array
⚙ 2. Creating Arrays with Built-In Functions
🔹 zeros(): Create array of zeros
Output:
2D zeros array:
🔹 ones(): Create array of ones
Output:
🔹 full(): Create array with a given value
Output:
🔢 3. Creating Number Sequences
🔹 Using arange() (like Python range)
Output:
🔹 Using linspace() (evenly spaced values)
Output:
🔁 4. Identity & Eye Matrices
🔹 identity()
Output:
🔹 eye() (identity with control over diagonal shift)
🎰 5. Random Arrays
Random integers:
📏 6. Creating Empty Array (Uninitialized memory)
⚠ Values are random (not zeros).
🧠 Summary Table
| Method | Purpose |
|---|---|
np.array() |
Create array from list or tuple |
np.zeros() |
Array filled with zeros |
np.ones() |
Array filled with ones |
np.full() |
Array with user-defined value |
np.arange() |
Create numeric range |
np.linspace() |
Create evenly spaced range |
np.identity() |
Identity matrix |
np.eye() |
Identity-like matrix |
np.random.rand() |
Random values |
np.random.randint() |
Random integers |
np.empty() |
Empty (uninitialized) array |
