Python Forum
Adding a row to a character array
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding a row to a character array
#1


m = np.chararray((10, 10))
m[:] = "*"
m(5, 4), m(5, 6) = "O", "O"
So I have the following character array:

Output:
m = [['*' '*' '*' '*' '*' '*' '*' '*' '*' '*'] ['*' '*' '*' '*' '*' '*' '*' '*' '*' '*'] ['*' '*' '*' '*' '*' '*' '*' '*' '*' '*'] ['*' '*' '*' '*' '*' '*' '*' '*' '*' '*'] ['*' '*' '*' '*' '*' '*' '*' '*' '*' '*'] ['*' '*' '*' '*' 'O' '*' 'O' '*' '*' '*'] ['*' '*' '*' '*' '*' '*' '*' '*' '*' '*'] ['*' '*' '*' '*' '*' '*' '*' '*' '*' '*'] ['*' '*' '*' '*' '*' '*' '*' '*' '*' '*'] ['*' '*' '*' '*' '*' '*' '*' '*' '*' '*']]
I want to insert a row at the beginning and the end. Specifically, I want the following character array:

Output:
m = [['X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X'] ['X' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' 'X'] ['X' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' 'X'] ['X' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' 'X'] ['X' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' 'X'] ['X' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' 'X'] ['X' '*' '*' '*' '*' 'O' '*' 'O' '*' '*' '*' 'X'] ['X' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' 'X'] ['X' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' 'X'] ['X' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' 'X'] ['X' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' 'X'] ['X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X' 'X']]
Adding the values of 'X' to the end of each row is easily done with an append. However, I cannot find any way of inserting an entire row to the beginning and the end of the array. Inserting an element to the beginning of each row is also proving difficult. Any ideas?
Reply


Messages In This Thread
Adding a row to a character array - by JoeB - Nov-23-2017, 12:06 PM
RE: Adding a row to a character array - by Larz60+ - Nov-23-2017, 12:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [solved] unexpected character after line continuation character paul18fr 4 3,493 Jun-22-2021, 03:22 PM
Last Post: deanhystad
  SyntaxError: unexpected character after line continuation character siteshkumar 2 3,233 Jul-13-2020, 07:05 PM
Last Post: snippsat
  how can i handle "expected a character " type error , when I input no character vivekagrey 2 2,792 Jan-05-2020, 11:50 AM
Last Post: vivekagrey
  Adding markers to Folium map only adding last element. tantony 0 2,168 Oct-16-2019, 03:28 PM
Last Post: tantony
  Replace changing string including uppercase character with lowercase character silfer 11 6,283 Mar-25-2019, 12:54 PM
Last Post: silfer
  Trouble adding LONG strings to an array or CSV output hariskr 1 2,243 Aug-02-2018, 11:29 PM
Last Post: woooee
  SyntaxError: unexpected character after line continuation character Saka 2 18,634 Sep-26-2017, 09:34 AM
Last Post: Saka

Forum Jump:

User Panel Messages

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