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 7566041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:18:41+00:00 2026-05-30T14:18:41+00:00

Say I have the following array: import numpy as np a = [‘hello’,’snake’,’plate’] I

  • 0

Say I have the following array:

import numpy as np
a = ['hello','snake','plate']

I want this to turn into a numpy array b so that:

b[0,0] = 'h'
b[0,1] = 'e'
b[0,2] = 'l'
b[1,0] = 's'
...

I want the standard numpy tricks to work, like broadcasting, comparison, etc.

How is it done? And where is this in the numpy documentation?

Thanks!

Uri

  • 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-05-30T14:18:42+00:00Added an answer on May 30, 2026 at 2:18 pm

    You can create a numpy character array directly e.g.:

    b = np.array([ ['h','e','l','l','o'],['s','n','a','k','e'],['p','l','a','t','e'] ])
    

    The usual array tricks work with this.

    If you have a and wish to generate b from it, note that:

    list('hello') == ['h','e','l','l','o']
    

    So you can do something like:

    b = np.array([ list(word) for word in a ])
    

    However, if a has words of unequal length (e.g. ['snakes','on','a','plane']), what do you want to do with the shorter words? You could pad them with spaces to the longest word:

    wid = max(len(w) for w in a)
    b = np.array([ list(w.center(wid)) for w in a])
    

    Which the string.center(width) pads with spaces, centering the string. You could also use rjust or ljust (see string docs).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have the following array in JavaScript: var skins = new Array('Light',
Say I have an array with the following members: car_porsche car_mercedes car_toyota motorcycle_suzuki motorcycle_honda
Lets say I have an array numbers that contains the following values: int numbers
Let's say we have following this: <p class=first>This is paragraph 1.</p> <p class=second>This is
Say we have the following array, $myArray , to check as per var_export: array
Lets say I have the following array: my_array = [1, 5, 8, 11, -6]
Lets say i have the following cstring char array[1000]; How i can convert it
say I have the following code: char[5][5] array; for(int i =0; i < 5;
Let's say I have any array Trial() As Integer I have two following variables
Say we have the following array of instantiated objects: SomeClass[] items = {new SomeClass(Apples,

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.