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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:19:49+00:00 2026-06-06T19:19:49+00:00

I have two different arrays, one with strings and another with ints. I want

  • 0

I have two different arrays, one with strings and another with ints. I want to concatenate them, into one array where each column has the original datatype. My current solution for doing this (see below) converts the entire array into dtype = string, which seems very memory inefficient.

combined_array = np.concatenate((A, B), axis = 1)

Is it possible to mutiple dtypes in combined_array when A.dtype = string and B.dtype = int?

  • 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-06-06T19:19:50+00:00Added an answer on June 6, 2026 at 7:19 pm

    One approach might be to use a record array. The "columns" won’t be like the columns of standard numpy arrays, but for most use cases, this is sufficient:

    >>> a = numpy.array(['a', 'b', 'c', 'd', 'e'])
    >>> b = numpy.arange(5)
    >>> records = numpy.rec.fromarrays((a, b), names=('keys', 'data'))
    >>> records
    rec.array([('a', 0), ('b', 1), ('c', 2), ('d', 3), ('e', 4)], 
          dtype=[('keys', '|S1'), ('data', '<i8')])
    >>> records['keys']
    rec.array(['a', 'b', 'c', 'd', 'e'], 
          dtype='|S1')
    >>> records['data']
    array([0, 1, 2, 3, 4])
    

    Note that you can also do something similar with a standard array by specifying the datatype of the array. This is known as a "structured array":

    >>> arr = numpy.array([('a', 0), ('b', 1)], 
                          dtype=([('keys', '|S1'), ('data', 'i8')]))
    >>> arr
    array([('a', 0), ('b', 1)], 
          dtype=[('keys', '|S1'), ('data', '<i8')])
    

    The difference is that record arrays also allow attribute access to individual data fields. Standard structured arrays do not.

    >>> records.keys
    chararray(['a', 'b', 'c', 'd', 'e'], 
          dtype='|S1')
    >>> arr.keys
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'numpy.ndarray' object has no attribute 'keys'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two different arrays. One array, a, for a list of people. My
I have two different buttons on my page. I want them both to be
I have two arrays containing different keys and values. However, some keys store strings
I've objects of array, in each object i have different type of strings in
I have a small application with two arrays. One array is the names, one
If I have two different arrays and all I can do is check whether
I'm trying to come up with a way combine two arrays that have different
I have following two arrays. I want the difference between these two arrays. That
I have two different libGL libraries on the same Ubuntu 11.04 machine. One library
I have two arrays in php $arrNum = array(1.7, 1.52, 0.01, 0.11); $arrStr =

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.