From:

array([ <16x16 sparse matrix of type '<type 'numpy.float64'>'

with 64 stored elements in Compressed Sparse Row format>], dtype=object)

I deduce that C is a 1 element dense array with dtype=object. That one element is a sparse matrix.

So I expect that

 C[0].toarray()  

will work. As the error says, a numpy array does not have a toarray method. But in this case its element does.

Since Gx and Gy are sparse, then you need to use the sparse versions of hstack and vstack, not the numpy versions. Check the type of A and B. I be those are numpy arrays, not sparse matrices.


Look what happens when I use np.hstack with a couple of sparse matrices:

In [70]: M=sparse.csr_matrix([[0,1,2],[2,3,4]])
In [71]: np.hstack([M,M])
/usr/lib/python3/dist-packages/scipy/sparse/compressed.py:298: SparseEfficiencyWarning: Comparing sparse matrices using >= and <= is inefficient, using <, >, or !=, instead.
  "using <, >, or !=, instead.", SparseEfficiencyWarning)
Out[71]: 
array([ <2x3 sparse matrix of type '<class 'numpy.int32'>'
    with 5 stored elements in Compressed Sparse Row format>,
       <2x3 sparse matrix of type '<class 'numpy.int32'>'
    with 5 stored elements in Compressed Sparse Row format>], dtype=object)

The result is not sparse, rather it dense with 2 sparse elements.

Answer from hpaulj on Stack Overflow
🌐
GitHub
github.com › aigamedev › scikit-neuralnetwork › issues › 83
'numpy.ndarray' object has no attribute 'todense' · Issue #83 · aigamedev/scikit-neuralnetwork
July 6, 2015 - and I got the following error: File "/usr/local/lib/python2.7/site-packages/sknn/dataset.py", line 113, in conv_fn = lambda x: x.todense().astype(theano.config.floatX) AttributeError: 'numpy.ndarray' object has no attribute 'todense' No one assigned · bug · No type ·
🌐
GitHub
github.com › numpy › numpy › issues › 14487
Unexpected behavior with csr matrices · Issue #14487 · numpy/numpy
September 11, 2019 - I also have unexpected behavior with csr matrices: import numpy as np from scipy.sparse import csr_matrix a = np.array([[1, 0, 2, 2], [1, 4, 2, 4]]) m = csr_matrix(a) m.shape Out: (2, 4) m.todense() Out: matrix([[1, 0, 2, 2], [1, 4, 2, 4...
Author   zjpoh
Discussions

python - Unable to convert a sparse matrix to a dense one - Stack Overflow
I want to visualize the solution, ... and C.todense(), but the answer is the following: In [391]: C Out[391]: array([ <16x16 sparse matrix of type '' with 64 stored elements in Compressed Sparse Row format>], dtype=object) In [392]: C.toarray() Traceback (most recent call last): File "", line 1, in C.toarray() AttributeError: 'numpy.ndarray' object has ... More on stackoverflow.com
🌐 stackoverflow.com
python - Why did it happen "AttributeError: 'matrix' object has no attribute 'todense'" - Stack Overflow
I want to run the alexnet CNN architecture with a tutorial example but I want to do epoch there is an error AttributeError: 'matrix' object has no attribute 'todense' cost_history=[] n_epochs =5 # ... More on stackoverflow.com
🌐 stackoverflow.com
python - AttributeError: 'numpy.ndarray' object has no attribute 'A' - Stack Overflow
I am trying to perform tfidf on a matrix. I would like to use gensim, but models.TfidfModel() only works on a corpus and therefore returns a list of lists of varying lengths (I want a matrix). The More on stackoverflow.com
🌐 stackoverflow.com
Python Coding help- keep recieving error message"AttributeError: 'numpy.ndarray' object has no attribute 'MESSAGE_A'"
You should not be accessing dataframe columns with the dot notation. This is one of the reasons why. Use uplift_df['MESSAGE_A']. More on reddit.com
🌐 r/learnpython
9
18
October 16, 2022
🌐
GitHub
github.com › bendemeo › shannonca › issues › 1
AttributeError: 'numpy.ndarray' object has no attribute 'todense' · Issue #1 · bendemeo/shannonca
When running the reducer I encounter this issue: AttributeError: 'numpy.ndarray' object has no attribute 'todense' Any specific version of numpy is required? using v1.19.2 Thanks
🌐
Stack Overflow
stackoverflow.com › questions › 74689845 › why-did-it-happen-attributeerror-matrix-object-has-no-attribute-todense
python - Why did it happen "AttributeError: 'matrix' object has no attribute 'todense'" - Stack Overflow
... Remove the line train_y = train_y.todense() from your code. This line is causing the error. Convert the train_y to a Numpy array - you can use it as current implemented (instead of a matrix).
🌐
Pydata
sparse.pydata.org › en › 0.7.0 › _modules › sparse › coo › core.html
sparse.coo.core — sparse 0.7.0+0.g1bdd137.dirty documentation
Examples -------- >>> x = np.eye(5) >>> s = COO.from_numpy(x) >>> s <COO: shape=(5, 5), dtype=float64, nnz=5, fill_value=0.0> >>> x[x == 0] = np.nan >>> COO.from_numpy(x, fill_value=np.nan) <COO: shape=(5, 5), dtype=float64, nnz=5, fill_value=nan> """ x = np.asanyarray(x).view(type=np.ndarray) if fill_value is None: fill_value = _zero_of_dtype(x.dtype) if x.shape: coords = np.where(~equivalent(x, fill_value)) data = x[coords] coords = np.vstack(coords) else: coords = np.empty((0, 1), dtype=np.uint8) data = np.array(x, ndmin=1) return cls(coords, data, shape=x.shape, has_duplicates=False, sorted=True, fill_value=fill_value) [docs] def todense(self): """ Convert this :obj:`COO` array to a dense :obj:`numpy.ndarray`. Note that this may take a large amount of memory if the :obj:`COO` object's :code:`shape` is large.
Find elsewhere
🌐
SciPy
docs.scipy.org › doc › scipy › reference › generated › scipy.sparse.csr_matrix.todense.html
todense — SciPy v1.17.0 Manual
If out was passed and was an array (rather than a numpy.matrix), it will be filled with the appropriate values and returned wrapped in a numpy.matrix object that shares the same memory.
🌐
Python
mail.python.org › pipermail › scipy-user › 2007-April › 011776.html
[SciPy-user] scipy compilation succeeds, test fails
April 21, 2007 - Steven, I did what you said, but unfortunately it still fails (I've re-built numpy as well): ====================================================================== ERROR: check_simple_todense (scipy.io.tests.test_mmio.test_mmio_coordinate) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/scipy/io/tests/test_mmio.py", line 151, in check_simple_todense b = mmread(fn).todense() AttributeError: 'numpy.ndarray' object has no attribute 'todense' ===============
🌐
Career Karma
careerkarma.com › blog › python › python attributeerror: ‘numpy.ndarray’ object has no attribute ‘append’ solution
Python AttributeError: 'numpy.ndarray' object has no attribute 'append' Solution
December 1, 2023 - In regular Python, you can use the append() method to add an item to the end of a list. You cannot use this method in NumPy. If you try to use the Python append() method to add an item to the end of a NumPy array, you will see the AttributeError: ‘numpy.ndarray’ object has no attribute ‘append’ error.
🌐
Reddit
reddit.com › r/learnpython › error creating numpy v-stack, 'attributeerror: 'numpy.ndarray' object has no attribute 'np'
r/learnpython on Reddit: Error creating numpy v-stack, 'AttributeError: 'numpy.ndarray' object has no attribute 'np'
May 4, 2021 -

Hi,

I'm trying to create a numpy v-stack and creating 3 np.array's for it, by filling them with a loop:

I get the error: 'AttributeError: 'numpy.ndarray' object has no attribute 'np' . I think I'm using the wrong notation to append to the empty arrays:

neighbor_id = [id_ for id_ in range(1, n_obs) if id_ != user_id]

neighbor_id_arr = np.array(neighbor_id)

similarity = np.array([])

num_interactions = np.array([])

# get similarity and num_interactions

for id_ in neighbor_id:

similarity.np.append(np.dot(user_item.loc[user_id],user_item.loc[id_])) #The issue is here, I think

num_interactions.np.append(user_interactions.loc[id_])

c = numpy.vstack((neighbor_id_arr, similarity,num_interactions))

Thanks!
James

🌐
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
🌐
Edureka Community
edureka.co › home › community › categories › python › attributeerror numpy ndarray object has no...
AttributeError numpy ndarray object has no attribute append | Edureka Community
August 10, 2020 - x_train=[] y_train=[] for i in range(8,64): x_train.append(trs[i-8:i,0]) ... ) AttributeError: 'numpy.ndarray' object has no attribute 'append'
🌐
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
Answer: The error is exactly what it says on the tin: NumPy’s ndarray object has no attribute [code ]append[/code] defined in its API. The error in question, for reference. We can start by asking, what is a numpy.ndarray? NumPy is an incredibly useful library for data manipulation in Python, wh...
🌐
GitHub
github.com › dpeerlab › Palantir › issues › 48
Error in palantir.utils.run_magic_imputation · Issue #48 · dpeerlab/Palantir
November 24, 2020 - Hi, when I run your tutorial on Palantir using your data, I run into this error when running magic imputation: imp_df = palantir.utils.run_magic_imputation(ad, dm_res) it results in: Traceback (most recent call last): File "<pyshell#23>", line 1, in <module> imp_df = palantir.utils.run_magic_imputation(ad, dm_res) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/palantir/utils.py", line 123, in run_magic_imputation data = pd.DataFrame(data.X.todense(), index=data.obs_names, columns=data.var_names) AttributeError: 'numpy.ndarray' object has no attribute 'todense'
Author   carloelle
🌐
GitHub
github.com › lmcinnes › umap › issues › 894
AttributeError: 'numpy.ndarray' object has no attribute 'transform' · Issue #894 · lmcinnes/umap
July 27, 2022 - Hello, When trying to do a .fit_transform on the "Train" data and then a .transform on the "Test" data, I get the error: AttributeError: 'numpy.ndarray' object has no at...
Author   rbsingh13