Python Forum
Tried to create a function in a Datacamp course - why a is not equal to x_copy?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tried to create a function in a Datacamp course - why a is not equal to x_copy?
#1
Can you run this and tell why a is not equal to x_copy?

    #Define x,y and swap_inds
    x = np.array([1, 2, 3, 4])
    y = np.array([4, 3, 2, 1])
    swap_inds = np.random.random(size=len(x)) < 0.5
    
    #Print out swap_inds
    print(swap_inds)
    
    #Method 1
    x_copy = np.copy(x)
    y_copy = np.copy(y)
    x_copy[swap_inds] = y[swap_inds]
    print(x_copy)
    
    #Method 2
    a = x_copy[swap_inds]
    b = y[swap_inds]
    a=b
    print(a)
Reply
#2
Line 18
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Bug New to coding, Using the zip() function to create Diret and getting weird results Shagamatula 6 1,438 Apr-09-2023, 02:35 PM
Last Post: Shagamatula
  python create function validation mg24 1 832 Nov-15-2022, 01:57 AM
Last Post: deanhystad
  create my exception to my function korenron 2 787 Nov-09-2022, 01:50 PM
Last Post: korenron
  Create a function for writing to SQL data to csv mg24 4 1,150 Oct-01-2022, 04:30 AM
Last Post: mg24
  Create SQL connection function and validate mg24 1 937 Sep-30-2022, 07:45 PM
Last Post: deanhystad
  is there equal syntax to "dir /s /b" kucingkembar 2 982 Aug-16-2022, 08:26 AM
Last Post: kucingkembar
  Can a variable equal 2 things? Extra 4 1,484 Jan-18-2022, 09:21 PM
Last Post: Extra
  How to define a function to create a resorted list? sparkt 6 2,812 Aug-08-2020, 04:10 PM
Last Post: sparkt
  How to make this function general to create binary numbers? (many nested for loops) dospina 4 4,404 Jun-24-2020, 04:05 AM
Last Post: deanhystad
  create function let_to_num() al_Czervik 2 2,112 Apr-17-2020, 10:44 PM
Last Post: al_Czervik

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020