For the following code, I am getting the error I have put in title:
import scipy.io as sio
import numpy as np
temp = np.load('temp.npy')
sio.savemat('final.mat',temp)
Although AttributeError
is a common error in python, I did not find anything useful for 'items'
as mentioned in the title. How can we fix this?
This error occurs when you attempt to append one or more values to the end of a NumPy array by using the append() function in regular Python. Since NumPy doesn't have an append attribute, an error is thrown. To fix this, you must use np. append() instead.
To convert a NumPy array (ndarray) to a Python list use ndarray. tolist() function, this doesn't take any parameters and returns a python list for an array. While converting to a list, it converts the items to the nearest compatible built-in Python type.
The main data structure in NumPy is the ndarray, which is a shorthand name for N-dimensional array. When working with NumPy, data in an ndarray is simply referred to as an array. It is a fixed-sized array in memory that contains data of the same type, such as integers or floating point values.
It takes a dict as the second argument not an array:
From the docs:
mdict : dict
Dictionary from which to save matfile variables.
I am not overly familiar but I imagine you pass the name as the key and the array as the value, something like:
sio.savemat('final.mat',{"foo":temp})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With