AttributeError: 'Series' object has no attribute 'as_matrix' in PyTorch 1.16

Mona_Jalal: <p>I am running a PyTorch code (2018 ish) with PyTorch 1.16 and I got the following error. Is there a quick fix for it?</p>
<pre><code class="lang-auto">landmarks_frame = pd.read_csv('faces/face_landmarks.csv')

n = 65 # Number of landmarks
img_name = landmarks_frame.iloc[n, 0]
landmarks = landmarks_frame.iloc[n, 1:].as_matrix()
landmarks = landmarks.astype('float').reshape(-1, 2)

print('Image name: {}'.format(img_name))
print('Landmarks shape: {}'.format(landmarks.shape))
print('First 4 Landmarks: {}'.format(landmarks[:4]))
</code></pre>
<p>the error is:</p>
<pre><code class="lang-auto">---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
&lt;ipython-input-3-8411fb211b60&gt; in &lt;module&gt;
      3 n = 65 # Number of landmarks
      4 img_name = landmarks_frame.iloc[n, 0]
----&gt; 5 landmarks = landmarks_frame.iloc[n, 1:].as_matrix()
      6 landmarks = landmarks.astype('float').reshape(-1, 2)
      7 

~/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py in __getattr__(self, name)
   5272             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   5273                 return self[name]
-&gt; 5274             return object.__getattribute__(self, name)
   5275 
   5276     def __setattr__(self, name: str, value) -&gt; None:

AttributeError: 'Series' object has no attribute 'as_matrix'
</code></pre>

Mona_Jalal: <p>The following works. I am not exactly sure why</p>
<pre><code class="lang-auto">landmarks_frame = pd.read_csv('faces/face_landmarks.csv')

##n = 65 # Number of landmarks
##img_name = landmarks_frame.iloc[n, 0]
##landmarks = landmarks_frame.iloc[n, 1:].as_matrix()
##landmarks = landmarks.astype('float').reshape(-1, 2)

##print('Image name: {}'.format(img_name))
##print('Landmarks shape: {}'.format(landmarks.shape))
##print('First 4 Landmarks: {}'.format(landmarks[:4]))




n = 65
img_name = landmarks_frame.iloc[n, 0]
landmarks = landmarks_frame.iloc[n, 1:]
landmarks = np.asarray(landmarks)
landmarks = landmarks.astype('float').reshape(-1, 2)

print('Image name: {}'.format(img_name))
print('Landmarks shape: {}'.format(landmarks.shape))
print('First 4 Landmarks: {}'.format(landmarks[:4]))
print('image name:', img_name)
</code></pre>

Nikronic: <p>Hi,</p>
<p>This is not PyTorch issue, it is related to Pandas and the issue is that <code>as_matrix</code> has been deprecated in favor of <code>to_numpy</code>.</p>
<aside class="onebox stackexchange">
  <header class="source">
      <a href="https://stackoverflow.com/questions/60164560/attributeerror-series-object-has-no-attribute-as-matrix-why-is-it-error" target="_blank" rel="noopener nofollow ugc">stackoverflow.com</a>
  </header>
  <article class="onebox-body">
      <a href="https://stackoverflow.com/users/12877198/yc-sang" target="_blank" rel="noopener nofollow ugc">
    <img alt="YC Sang" src="https://lh3.googleusercontent.com/a-/AAuE7mB_ZAR9f_slPbmx-E_UiC2aoLt8VQ89cHkJoh_p=k-s128" class="thumbnail onebox-avatar" width="60" height="60">
  </a>
<h4>
  <a href="https://stackoverflow.com/questions/60164560/attributeerror-series-object-has-no-attribute-as-matrix-why-is-it-error" target="_blank" rel="noopener nofollow ugc">AttributeError: 'Series' object has no attribute 'as_matrix' Why is it error?</a>
</h4>

<div class="tags">
  <strong>python, pandas, numpy</strong>
</div>

<div class="date">
  asked by
  
  <a href="https://stackoverflow.com/users/12877198/yc-sang" target="_blank" rel="noopener nofollow ugc">
    YC Sang
  </a>
  on <a href="https://stackoverflow.com/questions/60164560/attributeerror-series-object-has-no-attribute-as-matrix-why-is-it-error" target="_blank" rel="noopener nofollow ugc">08:21AM - 11 Feb 20 UTC</a>
</div>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>

<p>Bests</p>