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 Overflowpython - Unable to convert a sparse matrix to a dense one - Stack Overflow
python - Why did it happen "AttributeError: 'matrix' object has no attribute 'todense'" - Stack Overflow
python - AttributeError: 'numpy.ndarray' object has no attribute 'A' - Stack Overflow
Python Coding help- keep recieving error message"AttributeError: 'numpy.ndarray' object has no attribute 'MESSAGE_A'"
https://imgur.com/gallery/yAdAjdx
Hello,
Linked is the screenshot of the two error messages I keep recieving as well as the code leading up to it. I'm trying to run an uplift on a classification tree. Any help is appreciated, I am still fairly new to python. Thank you!!
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