Online education platform Coursera said on Wednesday it would buy rival Udemy for about $950 million in stock, giving the two companies more scale to compete as AI threatens their businesses.