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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:50:14+00:00 2026-05-24T13:50:14+00:00

When I try to assign a string to an array like this: CoverageACol[0,0] =

  • 0

When I try to assign a string to an array like this:

CoverageACol[0,0] = "Hello" 

I get the following error

Traceback (most recent call last):
  File "<pyshell#19>", line 1, in <module>
    CoverageACol[0,0] = "hello"
ValueError: setting an array element with a sequence.

However, assigning an integer does not result in an error:

CoverageACol[0,0] = 42

CoverageACol is a numpy array.

Please help! Thanks!

  • 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-24T13:50:15+00:00Added an answer on May 24, 2026 at 1:50 pm

    You get the error because NumPy’s array is homogeneous, meaning it is a multidimensional table of elements all of the same type. This is different from a multidimensional list-of-lists in "regular" Python, where you can have objects of different type in a list.

    Regular Python:

    >>> CoverageACol = [[0, 1, 2, 3, 4],
                        [5, 6, 7, 8, 9]]
     
    >>> CoverageACol[0][0] = "hello"
    
    >>> CoverageACol
        [['hello', 1, 2, 3, 4], 
         [5, 6, 7, 8, 9]]
    

    NumPy:

    >>> from numpy import *
    
    >>> CoverageACol = arange(10).reshape(2,5)
    
    >>> CoverageACol
        array([[0, 1, 2, 3, 4],
               [5, 6, 7, 8, 9]])
    
    >>> CoverageACol[0,0] = "Hello" 
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    
    /home/biogeek/<ipython console> in <module>()
    
    ValueError: setting an array element with a sequence.
    

    So, it depends on what you want to achieve, why do you want to store a string in an array filled for the rest with numbers? If that really is what you want, you can set the datatype of the NumPy array to string:

    >>> CoverageACol = array(range(10), dtype=str).reshape(2,5)
    
    >>> CoverageACol
        array([['0', '1', '2', '3', '4'],
               ['5', '6', '7', '8', '9']], 
               dtype='|S1')
    
    >>> CoverageACol[0,0] = "Hello"
    
    >>> CoverageACol
        array([['H', '1', '2', '3', '4'],
             ['5', '6', '7', '8', '9']], 
             dtype='|S1')
    

    Notice that only the first letter of Hello gets assigned. If you want the whole word to get assigned, you need to set an array-protocol type string:

    >>> CoverageACol = array(range(10), dtype='a5').reshape(2,5)
    
    >>> CoverageACol: 
        array([['0', '1', '2', '3', '4'],
               ['5', '6', '7', '8', '9']], 
               dtype='|S5')
    
    >>> CoverageACol[0,0] = "Hello"
    
    >>> CoverageACol
        array([['Hello', '1', '2', '3', '4'],
               ['5', '6', '7', '8', '9']], 
               dtype='|S5')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
We try to convert from string to Byte[] using the following Java code: String
try { ... } catch (SQLException sqle) { String theError = (sqle).getSQLState(); ... }
How do you assign the data fetched via getJSON() to an array, for later
I have a problem. This is my code. When i try to use the
Let me try to explain... Lets say I have the following 'a' tags on
i am currently trying to assign each character that i get from a file
I'm trying to store a string in an array contained within a struct, and
Coding in VB.Net Hi guys I've got this problem where I'm trying to assign
I try to implement a table function by following Tony Andrews example . But

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.