Why I am getting this error: object has no attribute 'astype'

Refresh

April 2019

Views

709 time

1

I have defined a function myfunc inside a python file myfile. when i import this function from a jupyter notebook, it is showing the following error:

import numpy as np
import os
from scipy.misc import imread
import ast
from myfile import myfunc
 .....
class_mask = np.equal(image, i)
class_mask = class_mask.astype(np.float32)
 .....
AttributeError: 'NotImplementedType' object has no attribute 'astype'

However, whenever I have the myfile content in a cell and running inside the jupyter, it is working without any problem? What is the reason for this error? Thanks

1 answers

0

We can only import function from a python module/file. A Jupyter Notebook when you save have an extention of .pynb, that means its not actually a python module.

Just open your Notebook with a text editor, you probably see html like content. Which is not possible for a python module to contain.

You rather want to export the Jupyter Notebook as Python Module in the same directory from where you are trying to run your current program.

File -> Export as Python File

Once exported you can use it as just any other python module. Hope it helps!