Python Forum
how to join by stack multiple types in numpy arrays
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to join by stack multiple types in numpy arrays
#2
numpy arrays have a data type. All elements in the array are that type. You cannot make a numpy array that has strings and integers.

That said, you can have a numpy array of structures.
import numpy as np
from numpy.lib import recfunctions

arr1 = np.array([1, 2, 3, 4, 5, 6, 7])
arr2 = np.array(["n", "b", "c", "y", "f", "j", "p"])

l = recfunctions.merge_arrays((arr1, arr2))
print(l)
Output:
[(1, 'n') (2, 'b') (3, 'c') (4, 'y') (5, 'f') (6, 'j') (7, 'p')]
Reply


Messages In This Thread
RE: how to join by stack multiple types in numpy arrays - by deanhystad - Jun-20-2022, 05:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem adding two numpy arrays djf123 2 2,129 Aug-09-2022, 08:31 PM
Last Post: deanhystad
  numpy.dot() result different with classic computation for large-size arrays geekgeek 5 1,946 Jan-25-2022, 09:45 PM
Last Post: Gribouillis
  Two numpy arrays Sandra2312 1 1,831 Jan-18-2021, 06:10 PM
Last Post: paul18fr
  The difference between os.path.join( and os.sep.join( Pedroski55 2 9,547 Nov-17-2020, 08:38 AM
Last Post: Pedroski55
  numpy in1d with two simple arrays claw91 3 2,622 Sep-21-2020, 12:43 PM
Last Post: scidam
  Deleting multiple variables/arrays Robotguy 0 1,522 Aug-18-2020, 09:56 PM
Last Post: Robotguy
  Type coercion with Numpy arrays Mark17 2 2,554 Jul-24-2020, 02:04 AM
Last Post: scidam
  filling and printing numpy arrays of str pjfarley3 4 3,343 Jun-07-2020, 09:09 PM
Last Post: pjfarley3
  Installing Numpy multiple locations dwhe 4 3,204 Dec-21-2019, 02:02 AM
Last Post: dwhe
  How to concatenate nested numpy arrays? python_newbie09 2 4,821 Apr-16-2019, 07:00 PM
Last Post: python_newbie09

Forum Jump:

User Panel Messages

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