Python Forum
Changing Values in a List
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing Values in a List
#1
I would like to replace all the values (1.3million) in column 3 with 0.00000000. Can someone please advise how I insert this in my code please?

file = 'Z_Before_After.txt'
data = np.genfromtxt(file)
xx = data[:, 0]
yy = data[:, 1]
elevation = data[:, 2]
initial = data[; 2]

with open(file, "w") as output:
    output.write(xx, yy, initial, elevation)
3560181.703 -3384947.321 -5.02245
3560191.703 -3384947.321 -4.88665
3560201.703 -3384947.321 -4.76042
3560211.703 -3384947.321 -4.66599
3560221.703 -3384947.321 -4.60876
3560231.703 -3384947.321 -4.55424
3560241.703 -3384947.321 -4.49973
3560251.703 -3384947.321 -4.35269
3560261.703 -3384947.321 -4.11991
Reply
#2
Try like
import numpy as np
data = np.array([[1,2,3],[4,5,6],[7,8,9]])
data[:, 2] = np.zeros(3)
data
Output:
array([[1, 2, 0], [4, 5, 0], [7, 8, 0]])
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Counter to keep track how many times values in a list appear in each row in a column chief 0 1,603 Mar-24-2020, 08:14 PM
Last Post: chief
  Get max values based on unique values in another list - python Antonio 8 8,417 Jun-12-2018, 07:49 PM
Last Post: Mekire
  Changing Function by Changing or without Changing its Parameters usmankhan 5 3,741 Jan-09-2018, 03:52 PM
Last Post: Windspar

Forum Jump:

User Panel Messages

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