- import numpy as np
- x = np.array([0, 1, 5, 10, 20, 30, 40, 50])
- y = np.array([1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100])
- if len(x) < len(y):
- z = y.copy()
- z[:len(x)] += x
- else:
- z = x.copy()
- z[:len(y)] += y
- print(z)
-
- Active Topics
-
-
- by Eli 11 hours ago Shared Images View the latest post Replies 6 Views 1450
- by Eli 1 day ago Re: What is in Your Mind? View the latest post Replies 728 Views 323261
- by Eli 2 days ago Dr Wahome: How World Health Organization (WHO) is Doing Bad Things View the latest post Replies 1 Views 55
- by Eli 3 days ago Introduction to Abstract Algebra View the latest post Replies 4 Views 10987
- by Eli 4 days ago All in One: YouTube, TED, X, Facebook and Instagram Reels, Videos, Images and Text Posts View the latest post Replies 333 Views 50569
- by Eli 4 days ago Generating SSH Key and Adding it to the ssh-agent for Authentication on GitHub View the latest post Replies 2 Views 1153
- by Eli 6 days ago Russia Invades Ukraine View the latest post Replies 668 Views 256737
- by Eli 1 week ago How AI Could Empower any Business View the latest post Replies 1 Views 297
- by Eli 1 week ago Pondering Big Cosmology Questions Through Lectures and Dialogues View the latest post Replies 35 Views 62148
- by Eli 1 week ago The U.S - China Rivalry, Taiwan and Hong Kong View the latest post Replies 1 Views 395
-
Adding Two Vectors with Different Sizes in Python
- Eli
- Senior Expert Member
- Reactions: 185
- Posts: 5450
- Joined: 9 years ago
- Location: Tanzania
- Has thanked: 75 times
- Been thanked: 88 times
- Contact:
Sometimes a need arises to add two Numpy arrays, which are simply vectors in mathematical terms, of different sizes. Suppose you have two Numpy arrays, x and y with differing lengths, then the logical and convenient way to add them is by the simple python code below.
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
-
- Similar Topics
- Replies
- Views
- Last post
-
- Information
-
Who is online
Users browsing this forum: No registered users and 0 guests