You have an array of bytestrings; dtype is S:

In [338]: arr=np.array((b'first_element', b'element'))
In [339]: arr
Out[339]: 
array([b'first_element', b'element'], 
      dtype='|S13')

astype easily converts them to unicode, the default string type for Py3.

In [340]: arr.astype('U13')
Out[340]: 
array(['first_element', 'element'], 
      dtype='<U13')

There is also a library of string functions - applying the corresponding str method to the elements of a string array

In [341]: np.char.decode(arr)
Out[341]: 
array(['first_element', 'element'], 
      dtype='<U13')

The astype is faster, but the decode lets you specify an encoding.

See also How to decode a numpy array of dtype=numpy.string_?

Answer from hpaulj on Stack Overflow
🌐
GitHub
github.com › keras-team › autokeras › issues › 766
AttributeError: 'numpy.ndarray' object has no attribute 'decode' · Issue #766 · keras-team/autokeras
September 10, 2019 - I am seeing following error message AttributeError Traceback (most recent call last) in 3 clf = ak.TextRegressor() 4 #clf.fit(x=X, y=y, validation_split=0, ...
Published   Sep 10, 2019
🌐
Reddit
reddit.com › r/learnpython › how to decode a numpy array of encoded literals/strings in python3?
r/learnpython on Reddit: How to decode a numpy array of encoded literals/strings in Python3?
November 2, 2016 -

In Python3, I have the follow numpy array of strings.

Each string in the numpy array is in the form b'MD18EEinstead ofMD18EE`.

e.g.

import numpy as np
print(array1)
(b'first_element', b'element',...)

Normally, one would use .decode('UTF-8') to decode these elements. However, if I try

array1 = array1.decode('UTF-8')

I get the following error:

AttributeError: 'numpy.ndarray' object has no attribute 'decode'

How do I decode these elements from a numpy array? (That is, I don't want b'')

🌐
GitHub
github.com › skjerns › mat7.3 › issues › 31
AttributeError: 'numpy.ndarray' object has no attribute 'encode' · Issue #31 · skjerns/mat7.3
February 10, 2022 - AttributeError: 'numpy.ndarray' object has no attribute 'encode'#31 · Copy link · D-B-Miller · opened · on Feb 10, 2022 · Issue body actions · Hi, I am attempting to load in a large MAT file (>3GB) which is >=v7.3. When I try and load in the file I get the following error ·
Author   D-B-Miller
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-fix-numpy-ndarray-object-has-no-attribute-append
How to Fix: ‘numpy.ndarray’ object has no attribute ‘append’ - GeeksforGeeks
November 28, 2021 - As in the output, we can see that initially, the NumPy array had 4 items (1, 2, 3, 4). After appending 5 to the list, it is reflected in the NumPy array. This is so because here the append function is used on NumPy and not on NumPy array object (numpy.ndarray).
Find elsewhere
🌐
Groups
rasterio.groups.io › g › main › topic › attributeerror › 104814395
AttributeError: 'numpy.ndarray' object has no attribute 'transform' when rasterio.mask()
March 9, 2024 - You logged in using a passkey from another device. For faster access next time, add a passkey to this device · Note: Your email address is included with the abuse report
🌐
Quora
quora.com › Why-do-I-get-numpy-ndarray-object-has-no-attribute-append-error
Why do I get “numpy.ndarray object has no attribute append error”? - Quora
This error occurs because numpy.ndarray objects do not implement the list method append — numpy arrays have a fixed size and their API differs from Python lists. Calling arr.append(...) raises AttributeError.
🌐
GitHub
github.com › onnx › sklearn-onnx › issues › 654
'numpy.bool_' object has no attribute 'encode' · Issue #654 · onnx/sklearn-onnx
May 28, 2021 - There was an error while loading. Please reload this page · I have a sklearn.neural_network.MLPClassifier() model, where each input has two float fields, and outputs a boolean. When I call the following code:
🌐
GitHub
github.com › langchain-ai › langchain › issues › 19504
PGVector - AttributeError: 'numpy.ndarray' object has no attribute 'embed_documents' · Issue #19504 · langchain-ai/langchain
March 25, 2024 - Traceback (most recent call last): File "/Users/raul/Documents/ai/test_vectors/app.py", line 25, in db = PGVector.from_documents(embedding=embeddings, documents=texts, collection_name=COLLECTION_NAME, connection_string=CONNECTION_STRING) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/raul/.pyenv/versions/3.11.8/lib/python3.11/site-packages/langchain_community/vectorstores/pgvector.py", line 1105, in from_documents return cls.from_texts( ^^^^^^^^^^^^^^^ File "/Users/raul/.pyenv/versions/3.11.8/lib/python3.11/site-packages/langchain_community/vectorstores/pgvector.py", line 975, in from_texts embeddings = embedding.embed_documents(list(texts)) ^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'numpy.ndarray' object has no attribute 'embed_documents'
Author   raulalhenacare
🌐
GitHub
github.com › waylandy › phosformer › issues › 1
'numpy.ndarray' object has no attribute 'numpy'. · Issue #1 · waylandy/phosformer
November 16, 2023 - Traceback (most recent call last): File "/Users/joshuasacher/phosformer/wip1_S234.py", line 17, in <module> predictions = Phosformer.predict_many( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/joshuasacher/phosformer/Phosformer/modules.py", line 204, in predict_many return np.array([i['pred'] for i in batch_job(kinases, peptides, **kwargs)]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/joshuasacher/phosformer/Phosformer/modules.py", line 204, in <listcomp> return np.array([i['pred'] for i in batch_job(kinases, peptides, **kwargs)]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/joshuasacher/phosformer/Phosformer/modules.py", line 96, in batch_job pred = softmax(result['logits'].cpu(), axis=1)[:,1].numpy() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'numpy.ndarray' object has no attribute 'numpy'.
Author   jrsacher
🌐
Neurostars
neurostars.org › community chat
AttributeError: 'numpy.ndarray' object has no attribute 'func' - Community Chat - Neurostars
September 1, 2022 - Hello, I am working on a subject on my local pc I did preprocessing through fmriprep on docker. I used the when I wanted to run import nibabel as nib from nibabel.testing import data_path import numpy as np from nilearn import datasets atlas = datasets.fetch_atlas_msdl() Loading atlas image stored in ‘maps’ atlas_filename = atlas[‘maps’] Loading atlas data stored in ‘labels’ labels = atlas[‘labels’] Load the functional datasets a = nib.load(’/home/roya/outputneww2/sub-1001/ses-01/...
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.char.decode.html
numpy.char.decode — NumPy v2.5.dev0 Manual
>>> import numpy as np >>> c = np.array([b'\x81\xc1\x81\xc1\x81\xc1', b'@@\x81\xc1@@', ... b'\x81\x82\xc2\xc1\xc2\x82\x81']) >>> c array([b'\x81\xc1\x81\xc1\x81\xc1', b'@@\x81\xc1@@', b'\x81\x82\xc2\xc1\xc2\x82\x81'], dtype='|S7') >>> np.strings.decode(c, encoding='cp037') array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')