Algorithm:
- Import NumPy library
- Create initial array with values [10, 20, 30, 40, 50]
- Print original array
- Append single element 60 using np.append()
- Print array after single append
- Append multiple elements [70, 80, 90] using np.append()
- Print array after multiple append
- Remove element at index 2 using np.delete()
- Print array after single deletion
- Remove elements at indices 0 and 1 using np.delete()
- Print final array
Hello, dear reader! 👋
Thanks for visiting my blog! I’m a student just like you, sharing what I learn to help others with Python programming. I hope my posts are useful for your studies! 😊
If you find this post helpful, please leave a comment—even just a few emojis will make my day! 🐍✨ Your feedback keeps me motivated to create more content for everyone. 🚀
Happy programming!
— Abhin Krishna, S01, EB Department, MEC
Pseudocode:
IMPORT numpy as np
# Create array
array = CREATE_ARRAY([10, 20, 30, 40, 50])
PRINT "Original Array:", array
# Append single element
array = APPEND(array, 60)
PRINT "Array after appending 60:", array
# Append multiple elements
array = APPEND(array, [70, 80, 90])
PRINT "Array after appending [70, 80, 90]:", array
# Remove single element
array = DELETE(array, index 2)
PRINT "Array after removing element at index 2:", array
# Remove multiple elements
array = DELETE(array, indices [0, 1])
PRINT "Final array:", array
Program:
import numpy as np
# 1. Creating a NumPy array
# Create a NumPy array (which is similar to a list in Python)
array = np.array([10, 20, 30, 40, 50])
print("Original Array:", array)
# 2. Appending Elements to the List
# NumPy doesn't have an append method like Python lists, but we can use np.append
# Appending a single element
array = np.append(array, 60)
print("Array after appending 60:", array)
# Appending multiple elements
array = np.append(array, [70, 80, 90])
print("Array after appending [70, 80, 90]:", array)
# 3. Removing Elements from the List
# NumPy doesn't have a remove method like Python lists, but we can use np.delete
# Removing an element by index
array = np.delete(array, 2) # Removes the element at index 2 (30 in this case)
print("Array after removing the element at index 2:", array)
# Removing multiple elements by indices
array = np.delete(array, [0, 1]) # Removes elements at index 0 and 1
print("Array after removing elements at indices 0 and 1:", array)
Flowchart:
flowchart TD
A([Start]) --> B[[Import NumPy]]
B --> C[Create array with values 10,20,30,40,50]
C --> D[/Print original array/]
D --> E[Append single element 60]
E --> F[/Print array/]
F --> G[Append multiple elements 70,80,90]
G --> H[/Print array/]
H --> I[Remove element at index 2]
I --> J[/Print array/]
J --> K[Remove elements at indices 0,1]
K --> L[/Print final array/]
L --> M([End])
Important!
If you find any mistakes in my code or flowchart, please comment below this post. I will be happy to correct them and clear up any doubts you may have.
Flowchart Image: