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

  • SEARCH
  • Home
  • 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 8243977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:41:32+00:00 2026-06-07T21:41:32+00:00

Is this a bug or a feature? import numpy as np a=b=c=0 print ‘a=’,a

  • 0

Is this a bug or a feature?

import numpy as np
a=b=c=0
print 'a=',a
print 'b=',b
print 'c=',c

a = 5
print 'a=',a
print 'b=',b
print 'c=',c

b = 3
print 'a=',a
print 'b=',b
print 'c=',c

x=y=z=np.zeros(5)
print 'x=',x
print 'y=',y
print 'z=',z

x[2]= 10
print 'x=',x
print 'y=',y
print 'z=',z

y[3]= 20
print 'x=',x
print 'y=',y
print 'z=',z

The output of the code shows me that the numpy initializations are clones of each other while python tends to treat them as independent variable.

a= 0
b= 0
c= 0
a= 5
b= 0
c= 0
a= 5
b= 3
c= 0
x= [ 0.  0.  0.  0.  0.]
y= [ 0.  0.  0.  0.  0.]
z= [ 0.  0.  0.  0.  0.]
x= [  0.   0.  10.   0.   0.]
y= [  0.   0.  10.   0.   0.]
z= [  0.   0.  10.   0.   0.]
x= [  0.   0.  10.  20.   0.]
y= [  0.   0.  10.  20.   0.]
z= [  0.   0.  10.  20.   0.]

I hope the problem is clear.
Is this a bug or a feature in numpy?

Regards

  • 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-07T21:41:34+00:00Added an answer on June 7, 2026 at 9:41 pm

    this is not a bug,, and it is not about numpy initialization, this is a python thing,,
    check id of both x,y & z in your case, they point to same element

    What your code is doing is multiple initialization in the same line, when this happens, only 1 object is created and all the variables refer to the same.

    See the below example, how rebinding helps…

    In [19]: a=b=[1,2,3]
    
    In [20]: a
    Out[20]: [1, 2, 3]
    
    In [21]: b
    Out[21]: [1, 2, 3]
    
    In [22]: a[1]
    Out[22]: 2
    
    In [23]: a[1] = 99
    
    In [24]: a
    Out[24]: [1, 99, 3]
    
    In [25]: b
    Out[25]: [1, 99, 3]
    
    In [26]: id(a)
    Out[26]: 27945880
    
    In [27]: id(b)
    Out[27]: 27945880
    
    In [28]: a = a[:]   # This is Rebinding 
    
    In [29]: a
    Out[29]: [1, 99, 3]
    
    In [30]: id(a)
    Out[30]: 27895568  # The id of the variable is changed
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I maintain an application that uses a (to me) surprising PHP quirk/bug/feature. Consider this
So I came across this feature/bug today and I'm struggling to wrap my head
UPDATE 2011.09.13 This bug has been resolved by Adobe. The example code below now
We have this bug that only appears 30% of the time for the Release
I am trying to detetct/work around this bug in RSS elements. That means I
I have recently discovered that I am affected by this bug http://www.mail-archive.com/mono-bugs@lists.ximian.com/msg71515.html Well, at
I had this nasty bug that disappeared in the past but now after quite
is this a bug or a feature? I've created an index on a tsvector
Recently stumbled upon this neat little bug or 'feature' in PHP: function myCmpFunc($a,$b) {
UPDATE 2 This is a known bug/feature with the way Ruby 1.9.2 loads files.

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.