Python Forum
filling and printing numpy arrays of str
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
filling and printing numpy arrays of str
#1
I am new to python but experienced in several other languages. I do not understand yet why numpy.full does not fill an array of strings with the string value I supply in the code.

Example code and output follows. OS is Win10-64 Pro, Python version is 3.8.3.

#!/usr/bin/env python
import numpy as np

class arstr:
    def __init__(self, asize, aval):
        self.strs = np.full([asize, asize, asize], aval, dtype=str)

Mystrs = arstr(3, " ? ")

for s in Mystrs.strs:
    print (s)

exit()
Output in a cmd.exe window follows.

Output:
C:\Testdir>python atest.py [[' ' ' ' ' '] [' ' ' ' ' '] [' ' ' ' ' ']] [[' ' ' ' ' '] [' ' ' ' ' '] [' ' ' ' ' ']] [[' ' ' ' ' '] [' ' ' ' ' '] [' ' ' ' ' ']]
Why are each of the array elements a single blank character and not the three-character string " ? " that I specified in the invocation of the class?

Thank you in advance for any help you can offer.

Peter
Reply


Messages In This Thread
filling and printing numpy arrays of str - by pjfarley3 - Jun-07-2020, 07:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pandas : problem with conditional filling of a column Xigris 2 703 Jul-22-2023, 11:44 AM
Last Post: Xigris
  problem adding two numpy arrays djf123 2 2,188 Aug-09-2022, 08:31 PM
Last Post: deanhystad
  how to join by stack multiple types in numpy arrays caro 1 1,200 Jun-20-2022, 05:02 PM
Last Post: deanhystad
  Numpy error while filling up matrix with Characters august 4 1,969 Apr-13-2022, 10:28 PM
Last Post: august
  numpy.dot() result different with classic computation for large-size arrays geekgeek 5 2,028 Jan-25-2022, 09:45 PM
Last Post: Gribouillis
  Two numpy arrays Sandra2312 1 1,857 Jan-18-2021, 06:10 PM
Last Post: paul18fr
  [SOLVED] Filling multidict from CSV file? Winfried 3 2,032 Oct-24-2020, 08:26 PM
Last Post: Winfried
  numpy in1d with two simple arrays claw91 3 2,667 Sep-21-2020, 12:43 PM
Last Post: scidam
  Type coercion with Numpy arrays Mark17 2 2,604 Jul-24-2020, 02:04 AM
Last Post: scidam
  printing class properties from numpy.ndarrays of objects pjfarley3 2 2,031 Jun-08-2020, 05:30 AM
Last Post: pjfarley3

Forum Jump:

User Panel Messages

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