Access all PythonObjects attributes

24 views
Skip to first unread message

Filipe Duarte

unread,
Jan 22, 2021, 1:35:23 PMJan 22
to Swift for TensorFlow
Hi, I have been using Python for machine learning research for time series data. I feel that I need to take another step to learn another and more performant programming language. In this sense, I found Julia and Swift for Tensorflow, which both seem to have a good foundation and promises to be an alternative for Python. 

I started to learn Swift's interoperability with Python on Google Colab notebooks, using NumPy and Scikit-learn. The problem is that I didn't find how to access all the PythonObjects attributes. For example, assuming that I fit a LinearRegression on some randomly NumPy array:

```
var reg = lm.LinearRegression()
reg.fit(X, Y)
print(reg)
```
output: 
LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False)

I would like to access the `reg`'s attributes but did not find how to do this.

Nicholas Gustafson

unread,
Jan 22, 2021, 3:34:22 PMJan 22
to Swift for TensorFlow, duart...@gmail.com
Hi, 

When you say you would like to access the `reg's attributes, what do you mean exactly? In python you access an objects attributes using the dotted-syntax, which you employed in your linear regression example. If you would like a list of all a python object's attributes you can use python's built in dir function. Try:

print(Python.dir(reg))

I hope that helps!

Filipe Duarte

unread,
Jan 22, 2021, 5:45:35 PMJan 22
to Swift for TensorFlow, nickc...@gmail.com, Filipe Duarte
Thanks! 
Reply all
Reply to author
Forward
0 new messages