Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8615413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:22:18+00:00 2026-06-12T05:22:18+00:00

I am learning Numpy as a substitute to Matlab. I am having problem mapping

  • 0

I am learning Numpy as a substitute to Matlab. I am having problem mapping Matlab function to Numpy. Program is to add two signals using Matlab

Matlab version :

function [y.d = sigadd(xl,nl,x2,n2)
% implements y(n) = xi(n)+x2(n)
% [y,nl - sigadd(xi,nl,x2,n2)
X
% xi = first sequence over nl
% x2 - second sequence over n2 (n2 can be different from nl)
%
n = min(min(n1) ,min(n2)) :max(max(nl) ,max(n2)) ; X duration of y(n)
yl - zeros(l,length(n)); y2 = yl;
yl(find((n>=min(nl))&(n<cmar(nl))-l))lxl;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y = yl+y2;

I have tried the following in Python :

def SigAdd(x1,n1,x2,n2):
    n_l =  min(min(n1),min(n2))
    n_h=  max(max(n1),max(n2))
    n = arange(n_l,n_h+1)
    y1 = zeros([1,len(n)],int)
    y2 = y1
    y1 = (argwhere((n>=min(n1))&(n<=max(n1)))==1)
    y1 = x1
    y2 = (argwhere((n>=min(n2))&(n<=max(n2)))==1)
    y2 = x2
    y = y1 + y2
    return y,n

Expected Results:

Example1: Arrays of unequal length

x1 = array([1,1,1,1,1])
x2 = array([1,1,1,1])
n1 = array([1,2,3,4,5])
n2 = array([1,2,3,4])
y,n = SigAdd(x1,n1,x2,n2)
>> y 
array[2,2,2,2,1]
>>n
array[1,2,3,4,5]

Example2:Arrays of equal length

x1 = array([1,1,1])
x2 = array([1,1,1])
n1 = array([1,2,3])
n2 = array([3,4,5])
y,n = SigAdd(x1,n1,x2,n2)
>> y 
array[1,1,2,1,1]
>>n
array[1,2,3,4,5]

It works fine if both the arrays are of equal length, but won’t work for unequal arrays. I know the problem is i am overriding the y1 (which i initially created with zeros) with value of x1 causing problem. I have used argwhere command in Numpy which is equivalent to Find command of Matlab, but if I use it like Matlab program shown above, it shows error that value can’t be assigned to callable function.

Basically in Matlab program, unequal arrays are filled with zero’s. Matlab version handles condition even if two signals are of equal length but are at different positions. I want to use Python instead of Matlab but these conversion problems are causing pain.

Some Modifications : (But is not working, Indexing Error : Out of bound coming)

def SigAdd(x1,n1,x2,n2):
    n_l =  min(min(n1),min(n2))
    n_h=  max(max(n1),max(n2))
    n = arange(n_l,n_h+1)
    y1 = zeros([1,len(n)],int)
    y2 = y1
    y11 = argwhere((n>=min(n1))&(n<=max(n1)))
    q = 0
    for w in y11:
        y1[w]= x1[q]
        q = q + 1
    y22 = argwhere((n>=min(n2))&(n<=max(n2)))
    q = 0
    for w in y22:
        y2[w]= x2[q]
        q = q + 1
    y = y1 + y2
    return y
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:22:20+00:00Added an answer on June 12, 2026 at 5:22 am

    You can assign to a slice:

    def SigAdd(x1,n1,x2,n2):
        n_l = min(n1[0], n2[0])
        n_h = max(n1[-1], n2[-1])
        n = arange(n_l, n_h+1)
        y = zeros(len(n), int)
        i = n1[0] - n[0]
        y[i:i+len(x1)] = x1
        i = n2[0] - n[0]
        y[i:i+len(x2)] += x2
        return y
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am in the processing of learning python after using Matlab for years. I've
Learning haskell and want a function to generate a 2D grid similar to how
Learning flex, What would be the appropriate way to add some AS in a
I'm learning to use Numpy and I wanted to see the speed difference in
I'm a C and MATLAB user. When I started learning Python (a week ago)
Learning jquery, so please be kind :) Using PHP, I have a table with
Learning spine.js I completed both the tutorials no problem, seems like a great framework,
I am learning Python and numpy, and am new to the idea of duck
Learning about ARM NEON intrinsics, I was timing a function that I wrote to
Project Euler #101 I just started learning Numpy and it so far looks pretty

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.